Update README.md
Browse files
README.md
CHANGED
@@ -53,9 +53,12 @@ prompt_engine = MRPromptV3()
|
|
53 |
|
54 |
sys_prompt = 'You are a helpful AI assistant built by MediaTek Research. The user you are helping speaks Traditional Chinese and comes from Taiwan.'
|
55 |
|
56 |
-
def _inference(
|
57 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
58 |
-
|
|
|
|
|
|
|
59 |
output_str = tokenizer.decode(output_tensors[0])
|
60 |
return output_str
|
61 |
```
|
@@ -69,7 +72,7 @@ conversations = [
|
|
69 |
]
|
70 |
|
71 |
prompt = prompt_engine.get_prompt(conversations)
|
72 |
-
output_str = _inference(
|
73 |
result = prompt_engine.parse_generated_str(output_str)
|
74 |
print(result)
|
75 |
# {'role': 'assistant', 'content': '深度學習是一種人工智慧技術,主要是透過模仿生物神經網路的結構和功能來實現。它利用大量數據進行訓練,以建立複雜的模型並使其能夠自主學習、預測或分類輸入資料。\n\n在深度學習中,通常使用多層的神經網路,每一層都包含許多相互連接的節點(稱為神經元)。這些神經元可以處理不同特徵的輸入資料,並將結果傳遞給下一層的神經元。隨著資料流向更高層次,這個過程逐漸捕捉到更抽象的概念或模式。\n\n深度學習已被廣泛應用於各種領域,如圖像識別、自然語言處理、語音識別以及遊戲等。它提供了比傳統機器學習方法更好的表現,因為它能夠從複雜且非線性的數據中提取出有用的資訊。'}
|
@@ -78,7 +81,24 @@ print(result)
|
|
78 |
## Feature: Visual Instruction Following
|
79 |
|
80 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
|
|
|
|
|
|
82 |
```
|
83 |
|
84 |
|
@@ -122,7 +142,7 @@ conversations = [
|
|
122 |
|
123 |
prompt = prompt_engine.get_prompt(conversations, functions=functions)
|
124 |
|
125 |
-
output_str = _inference(
|
126 |
result = prompt_engine.parse_generated_str(output_str)
|
127 |
|
128 |
print(result)
|
@@ -152,7 +172,7 @@ conversations.append(
|
|
152 |
|
153 |
prompt = prompt_engine.get_prompt(conversations, functions=functions)
|
154 |
|
155 |
-
output_str2 = _inference(
|
156 |
result2 = prompt_engine.parse_generated_str(output_str2)
|
157 |
print(result2)
|
158 |
# {'role': 'assistant', 'content': '台北目前的溫度是攝氏30度。'}
|
|
|
53 |
|
54 |
sys_prompt = 'You are a helpful AI assistant built by MediaTek Research. The user you are helping speaks Traditional Chinese and comes from Taiwan.'
|
55 |
|
56 |
+
def _inference(tokenizer, model, generation_config, prompt, pixel_values=None):
|
57 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
58 |
+
if pixel_values is None:
|
59 |
+
output_tensors = model.generate(**inputs, generation_config=generation_config)
|
60 |
+
else:
|
61 |
+
output_tensors = model.generate(**inputs, generation_config=generation_config, pixel_values=pixel_values.to(model.dtype))
|
62 |
output_str = tokenizer.decode(output_tensors[0])
|
63 |
return output_str
|
64 |
```
|
|
|
72 |
]
|
73 |
|
74 |
prompt = prompt_engine.get_prompt(conversations)
|
75 |
+
output_str = _inference(tokenizer, model, generation_config, prompt)
|
76 |
result = prompt_engine.parse_generated_str(output_str)
|
77 |
print(result)
|
78 |
# {'role': 'assistant', 'content': '深度學習是一種人工智慧技術,主要是透過模仿生物神經網路的結構和功能來實現。它利用大量數據進行訓練,以建立複雜的模型並使其能夠自主學習、預測或分類輸入資料。\n\n在深度學習中,通常使用多層的神經網路,每一層都包含許多相互連接的節點(稱為神經元)。這些神經元可以處理不同特徵的輸入資料,並將結果傳遞給下一層的神經元。隨著資料流向更高層次,這個過程逐漸捕捉到更抽象的概念或模式。\n\n深度學習已被廣泛應用於各種領域,如圖像識別、自然語言處理、語音識別以及遊戲等。它提供了比傳統機器學習方法更好的表現,因為它能夠從複雜且非線性的數據中提取出有用的資訊。'}
|
|
|
81 |
## Feature: Visual Instruction Following
|
82 |
|
83 |
```python
|
84 |
+
conversations = [
|
85 |
+
# {"role": "system", "content": sys_prompt},
|
86 |
+
{"role": "user", "content": [
|
87 |
+
{
|
88 |
+
"type": "image",
|
89 |
+
"image_path": "image.jpg",
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"type": "text",
|
93 |
+
"text": "請問這是哪裡?"
|
94 |
+
},
|
95 |
+
]},
|
96 |
+
]
|
97 |
|
98 |
+
prompt, pixel_values = prompt_engine.get_prompt(conversations)
|
99 |
+
output_str = _inference(tokenizer, model, generation_config, prompt, pixel_values=pixel_values)
|
100 |
+
result = prompt_engine.parse_generated_str(output_str)
|
101 |
+
print(result)
|
102 |
```
|
103 |
|
104 |
|
|
|
142 |
|
143 |
prompt = prompt_engine.get_prompt(conversations, functions=functions)
|
144 |
|
145 |
+
output_str = _inference(tokenizer, model, generation_config, prompt)
|
146 |
result = prompt_engine.parse_generated_str(output_str)
|
147 |
|
148 |
print(result)
|
|
|
172 |
|
173 |
prompt = prompt_engine.get_prompt(conversations, functions=functions)
|
174 |
|
175 |
+
output_str2 = _inference(tokenizer, model, generation_config, prompt)
|
176 |
result2 = prompt_engine.parse_generated_str(output_str2)
|
177 |
print(result2)
|
178 |
# {'role': 'assistant', 'content': '台北目前的溫度是攝氏30度。'}
|