Update README.md
#2
by
shuo-yan
- opened
README.md
CHANGED
|
@@ -42,6 +42,45 @@ SPARK is a novel reinforcement learning framework that enables autonomous strate
|
|
| 42 |
| ScienceWorld L2 | **49.2%** | 33.6% | 30.5% |
|
| 43 |
| WebShop | **75.8%** | 29.7% | 32.0% |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
## Citation
|
| 46 |
|
| 47 |
If you use this model or the SPARK framework in your research, please cite:
|
|
|
|
| 42 |
| ScienceWorld L2 | **49.2%** | 33.6% | 30.5% |
|
| 43 |
| WebShop | **75.8%** | 29.7% | 32.0% |
|
| 44 |
|
| 45 |
+
## Quickstart
|
| 46 |
+
Here we provide a transformers inference style:
|
| 47 |
+
```python
|
| 48 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 49 |
+
|
| 50 |
+
model_name = "Jinyang23/Spark-1.5B-ScienceWorld"
|
| 51 |
+
|
| 52 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 53 |
+
model_name,
|
| 54 |
+
torch_dtype="auto",
|
| 55 |
+
device_map="auto"
|
| 56 |
+
)
|
| 57 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 58 |
+
|
| 59 |
+
prompt = "Calculate the sum of 123 and 456. Provide only the numerical answer."
|
| 60 |
+
|
| 61 |
+
messages = [
|
| 62 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
|
| 63 |
+
{"role": "user", "content": prompt}
|
| 64 |
+
]
|
| 65 |
+
text = tokenizer.apply_chat_template(
|
| 66 |
+
messages,
|
| 67 |
+
tokenize=False,
|
| 68 |
+
add_generation_prompt=True
|
| 69 |
+
)
|
| 70 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 71 |
+
|
| 72 |
+
generated_ids = model.generate(
|
| 73 |
+
**model_inputs,
|
| 74 |
+
max_new_tokens=512
|
| 75 |
+
)
|
| 76 |
+
generated_ids = [
|
| 77 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 81 |
+
print(response)
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
## Citation
|
| 85 |
|
| 86 |
If you use this model or the SPARK framework in your research, please cite:
|