File size: 3,026 Bytes
f404246 c25e918 f404246 ea24226 f404246 400b900 f404246 c25e918 f404246 c25e918 f404246 c25e918 f404246 c25e918 f404246 c25e918 f404246 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
---
base_model: google/gemma-3-4b-it
library_name: transformers
model_name: output
tags:
- generated_from_trainer
- trl
- sft
licence: license
license: apache-2.0
language:
- vi
- en
pipeline_tag: image-text-to-text
---
# Introduction
This model is a fine-tuned version of [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it) optimized for query rewriting based on conversation history to enhance conversational retrieval and question answering.
It has been trained using [TRL](https://github.com/huggingface/trl).
## Quick start
```python
from transformers import AutoTokenizer, Gemma3ForConditionalGeneration
MODEL_PATH = "r1ck/gemma-3-4b-it-rw"
model = Gemma3ForConditionalGeneration.from_pretrained(
MODEL_PATH, device_map="auto", attn_implementation='eager'
).eval()
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
prompt_template = """Given a conversation between (user, assistant) and a follow-up message from user, your task is to rewrite the follow-up message to a standalone message that captures all relevant context from the conversation.
Consume the entire conversation and follow-up message and think deeply about it. If the follow-up message is already clear, don't need to rewrite it, just return the original message. The rewritten message must be in Vietnamese.
# Conversation:
user: Hà Nội có những đặc điểm văn hóa nào nổi bật từ lịch sử?
assistant: Hà Nội, với lịch sử là kinh đô của Việt Nam, đã hội tụ nhiều tinh hoa văn hóa từ miền Bắc và cả nước. Thành phố này là nơi quy tụ của những nhân vật ưu tú, thương nhân, nghệ nhân, và thợ thủ công lành nghề từ khắp nơi. Họ mang theo phong tục, tập quán địa phương của mình, từ đó tạo nên nét văn hóa đặc trưng cho Hà Nội.
# Follow-up message:
Điều này mang lại lợi ích gì về du lịch?
# Rewritten message:
"""
inputs = tokenizer(
[prompt_template],
return_tensors="pt"
).to("cuda")
outputs = model.generate(
input_ids=inputs.input_ids,
attention_mask=inputs.attention_mask,
max_new_tokens=2048,
eos_token_id=tokenizer.eos_token_id,
use_cache=True,
)
response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
print(response[0])
```
## Training procedure
This model was trained with SFT For: Query rewrite based on conversation history task
### Framework versions
- TRL: 0.16.1
- Transformers: 4.50.0.dev0
- Pytorch: 2.6.0
- Datasets: 3.5.0
- Tokenizers: 0.21.1
## Citations
Cite TRL as:
```bibtex
@misc{vonwerra2022trl,
title = {{TRL: Transformer Reinforcement Learning}},
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
year = 2020,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/huggingface/trl}}
}
``` |