Image-Text-to-Text
Transformers
Safetensors
sentence-transformers
English
French
qwen3_5
reranker
cross-encoder
multimodal
text-ranking
document-reranking
vidore
beir
conversational
🇪🇺 Region: EU
Instructions to use lightonai/LightOn-rerank-PW-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lightonai/LightOn-rerank-PW-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="lightonai/LightOn-rerank-PW-4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("lightonai/LightOn-rerank-PW-4B") model = AutoModelForMultimodalLM.from_pretrained("lightonai/LightOn-rerank-PW-4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - sentence-transformers
How to use lightonai/LightOn-rerank-PW-4B with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("lightonai/LightOn-rerank-PW-4B") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lightonai/LightOn-rerank-PW-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lightonai/LightOn-rerank-PW-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lightonai/LightOn-rerank-PW-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/lightonai/LightOn-rerank-PW-4B
- SGLang
How to use lightonai/LightOn-rerank-PW-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "lightonai/LightOn-rerank-PW-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lightonai/LightOn-rerank-PW-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "lightonai/LightOn-rerank-PW-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lightonai/LightOn-rerank-PW-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use lightonai/LightOn-rerank-PW-4B with Docker Model Runner:
docker model run hf.co/lightonai/LightOn-rerank-PW-4B
| {%- set default_system = "Judge whether the document is relevant to the query. Answer Yes or No." -%} | |
| {%- set ns = namespace(system_text="", doc_visual=false, doc_text=false) -%} | |
| {%- for message in messages if message.role == "system" -%} | |
| {%- if message.content is string -%} | |
| {%- set ns.system_text = ns.system_text + message.content -%} | |
| {%- else -%} | |
| {%- for content in message.content -%} | |
| {%- if 'text' in content -%} | |
| {%- set ns.system_text = ns.system_text + content.text -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- if not ns.system_text -%} | |
| {%- set ns.system_text = default_system -%} | |
| {%- endif -%} | |
| {%- for message in messages if message.role == "document" -%} | |
| {%- if message.content is string -%} | |
| {%- if message.content -%} | |
| {%- set ns.doc_text = true -%} | |
| {%- endif -%} | |
| {%- else -%} | |
| {%- for content in message.content -%} | |
| {%- if content.type == 'image' or 'image' in content or 'image_url' in content or content.type == 'video' or 'video' in content -%} | |
| {%- set ns.doc_visual = true -%} | |
| {%- elif 'text' in content and content.text -%} | |
| {%- set ns.doc_text = true -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- macro render_content(message) -%} | |
| {%- if message.content is string -%} | |
| {{- message.content -}} | |
| {%- else -%} | |
| {%- for content in message.content -%} | |
| {%- if content.type == 'image' or 'image' in content or 'image_url' in content -%} | |
| {{- '<|vision_start|><|image_pad|><|vision_end|>' -}} | |
| {%- elif content.type == 'video' or 'video' in content -%} | |
| {{- '<|vision_start|><|video_pad|><|vision_end|>' -}} | |
| {%- elif 'text' in content -%} | |
| {{- content.text -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endmacro -%} | |
| {%- macro render_visuals(message) -%} | |
| {%- if message.content is not string -%} | |
| {%- for content in message.content -%} | |
| {%- if content.type == 'image' or 'image' in content or 'image_url' in content -%} | |
| {{- '<|vision_start|><|image_pad|><|vision_end|>' -}} | |
| {%- elif content.type == 'video' or 'video' in content -%} | |
| {{- '<|vision_start|><|video_pad|><|vision_end|>' -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endmacro -%} | |
| {%- macro render_texts(message) -%} | |
| {%- if message.content is string -%} | |
| {{- message.content -}} | |
| {%- else -%} | |
| {%- for content in message.content -%} | |
| {%- if content.type != 'image' and 'image' not in content and 'image_url' not in content and content.type != 'video' and 'video' not in content and 'text' in content -%} | |
| {{- content.text -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endmacro -%} | |
| {%- set user_body -%} | |
| {%- if ns.doc_visual -%} | |
| {%- for message in messages if message.role == "document" -%} | |
| {{- render_visuals(message) -}} | |
| {%- endfor -%} | |
| {{- 'Given a query, determine if the document image is relevant. The query is: ' -}} | |
| {%- for message in messages if message.role == "query" -%} | |
| {{- render_content(message) -}} | |
| {%- endfor -%} | |
| {%- if ns.doc_text -%} | |
| {{- '\n\nDocument: ' -}} | |
| {%- for message in messages if message.role == "document" -%} | |
| {{- render_texts(message) -}} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- else -%} | |
| {{- 'Given a query, determine if the document is relevant. The query is: ' -}} | |
| {%- for message in messages if message.role == "query" -%} | |
| {{- render_content(message) -}} | |
| {%- endfor -%} | |
| {{- '\n\nDocument: ' -}} | |
| {%- for message in messages if message.role == "document" -%} | |
| {{- render_content(message) -}} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- endset -%} | |
| {{- '<|im_start|>system\n' + ns.system_text|trim + '<|im_end|>\n' -}} | |
| {{- '<|im_start|>user\n' + user_body|trim + '<|im_end|>\n' -}} | |
| {%- if add_generation_prompt -%} | |
| {{- '<|im_start|>assistant\n<think>\n\n</think>\n\n' -}} | |
| {%- endif -%} | |