r1ck commited on
Commit
fb5d565
·
verified ·
1 Parent(s): 741f3d2
Files changed (1) hide show
  1. README.md +43 -7
README.md CHANGED
@@ -7,22 +7,58 @@ tags:
7
  - trl
8
  - sft
9
  licence: license
 
 
 
 
10
  ---
11
 
12
- # Model Card for output
13
 
14
- This model is a fine-tuned version of [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it).
15
  It has been trained using [TRL](https://github.com/huggingface/trl).
16
 
17
  ## Quick start
18
 
19
  ```python
20
- from transformers import pipeline
21
 
22
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
- generator = pipeline("text-generation", model="r1ck/output", device="cuda")
24
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
- print(output["generated_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ```
27
 
28
  ## Training procedure
 
7
  - trl
8
  - sft
9
  licence: license
10
+ license: mit
11
+ language:
12
+ - vi
13
+ pipeline_tag: text-generation
14
  ---
15
 
16
+ # Introduction
17
 
18
+ 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.
19
  It has been trained using [TRL](https://github.com/huggingface/trl).
20
 
21
  ## Quick start
22
 
23
  ```python
24
+ from transformers import AutoTokenizer, Gemma3ForConditionalGeneration
25
 
26
+
27
+ MODEL_PATH = "r1ck/gemma-3-4b-it-rw"
28
+
29
+ model = Gemma3ForConditionalGeneration.from_pretrained(
30
+ MODEL_PATH, device_map="auto", attn_implementation='eager'
31
+ ).eval()
32
+
33
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
34
+
35
+ 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.
36
+ 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.
37
+
38
+ # Conversation:
39
+ user: Hà Nội có những đặc điểm văn hóa nào nổi bật từ lịch sử?
40
+ 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.
41
+
42
+ # Follow-up message:
43
+ Điều này mang lại lợi ích gì về du lịch?
44
+
45
+ # Rewritten message:
46
+ """
47
+
48
+ inputs = tokenizer(
49
+ [prompt_template],
50
+ return_tensors="pt"
51
+ ).to("cuda")
52
+
53
+ outputs = model.generate(
54
+ input_ids=inputs.input_ids,
55
+ attention_mask=inputs.attention_mask,
56
+ max_new_tokens=2048,
57
+ eos_token_id=tokenizer.eos_token_id,
58
+ use_cache=True,
59
+ )
60
+ response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
61
+ print(response[0])
62
  ```
63
 
64
  ## Training procedure