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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
metrics:
|
| 6 |
+
- accuracy
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
|
| 9 |
+
model-index:
|
| 10 |
+
- name: Qwen2-Simple-Arguments
|
| 11 |
+
results:
|
| 12 |
+
- task:
|
| 13 |
+
type: text-generation
|
| 14 |
+
dataset:
|
| 15 |
+
name: Argument-parsing
|
| 16 |
+
type: Argument-parsing
|
| 17 |
+
metrics:
|
| 18 |
+
- name: Accuracy
|
| 19 |
+
type: Accuracy
|
| 20 |
+
value: 100
|
| 21 |
+
---
|
| 22 |
+
# Qwen2 Simple Arguments
|
| 23 |
+

|
| 24 |
+
[](https://www.freelancer.com/u/cdesivo92)
|
| 25 |
+
|
| 26 |
+
This model aims to parse simple english arguments, arguments formed of two premises and a conclusion, including two propositions.
|
| 27 |
+
|
| 28 |
+
## Model Details
|
| 29 |
+
|
| 30 |
+
### Model Description
|
| 31 |
+
|
| 32 |
+
<!-- Provide a longer summary of what this model is. -->
|
| 33 |
+
|
| 34 |
+
- **Developed by:** Cristian Desivo
|
| 35 |
+
- **Model type:** LLM
|
| 36 |
+
- **Language(s) (NLP):** English
|
| 37 |
+
- **License:** Apache-2.0
|
| 38 |
+
- **Finetuned from model:** Qwen2-0.5b
|
| 39 |
+
|
| 40 |
+
### Model Sources
|
| 41 |
+
|
| 42 |
+
<!-- Provide the basic links for the model. -->
|
| 43 |
+
|
| 44 |
+
- **Repository:** TBD
|
| 45 |
+
- **Demo:** TBD
|
| 46 |
+
|
| 47 |
+
### Quantization
|
| 48 |
+
|
| 49 |
+
- **Q4_K_M.gguf** https://huggingface.co/cris177/Qwen2-Simple-Arguments/resolve/main/Qwen2_arguments.Q4_K_M.gguf?download=true
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
Below we share some code snippets on how to get quickly started with running the model.
|
| 54 |
+
|
| 55 |
+
### llama.cpp server [Recommended]
|
| 56 |
+
|
| 57 |
+
The recommended way of running the model is with a llama.cpp server running the quantized https://huggingface.co/cris177/Qwen2-Simple-Arguments/resolve/main/Qwen2_arguments.Q4_K_M.gguf?download=true
|
| 58 |
+
|
| 59 |
+
Then you can use the following script to use the server's model for inference:
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
import json
|
| 63 |
+
import requests
|
| 64 |
+
|
| 65 |
+
def llmCompletion(prompt, **args):
|
| 66 |
+
url = "http://localhost:8080/completions"
|
| 67 |
+
headers = {
|
| 68 |
+
"Content-Type": "application/json"
|
| 69 |
+
}
|
| 70 |
+
data = {
|
| 71 |
+
'prompt': prompt
|
| 72 |
+
}
|
| 73 |
+
for arg in args:
|
| 74 |
+
data[arg] = args[arg]
|
| 75 |
+
response = requests.post(url, headers=headers, json=data)
|
| 76 |
+
return response.json()
|
| 77 |
+
|
| 78 |
+
def analyze_argument(argument):
|
| 79 |
+
instruction = 'Based on the following argument, identify the following elements: premises, conclusion, propositions, type of argument, negation of propositions and validity.'
|
| 80 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 81 |
+
|
| 82 |
+
### Instruction:
|
| 83 |
+
{}
|
| 84 |
+
|
| 85 |
+
### Input:
|
| 86 |
+
{}
|
| 87 |
+
|
| 88 |
+
### Response:"""
|
| 89 |
+
prompt = alpaca_prompt.format(instruction, argument)
|
| 90 |
+
with open("prompt.txt", "w") as f:
|
| 91 |
+
f.write(prompt)
|
| 92 |
+
properties = {
|
| 93 |
+
"Premise 1": {"type": "string"},
|
| 94 |
+
"Premise 2": {"type": "string"},
|
| 95 |
+
"Conclusion": {"type": "string"},
|
| 96 |
+
"Proposition 1": {"type": "string"},
|
| 97 |
+
"Proposition 2": {"type": "string"},
|
| 98 |
+
"Type of argument": {"type": "string"},
|
| 99 |
+
"Negation of Proposition 1": {"type": "string"},
|
| 100 |
+
"Negation of Proposition 2": {"type": "string"},
|
| 101 |
+
"Validity": {"type": "boolean"},
|
| 102 |
+
}
|
| 103 |
+
analysis = llmCompletion(prompt,
|
| 104 |
+
max_tokens=1000,
|
| 105 |
+
temperature=0,
|
| 106 |
+
json_schema={
|
| 107 |
+
"type": "object",
|
| 108 |
+
"properties": properties,
|
| 109 |
+
"required": list(properties.keys()),
|
| 110 |
+
},
|
| 111 |
+
)
|
| 112 |
+
return analysis['content']
|
| 113 |
+
|
| 114 |
+
argument = "If it's wednesday it's cold, and it's cold, therefore it's wednesday."
|
| 115 |
+
output = analyze_argument("If it's wednesday it's cold, and it's cold, therefore it's wednesday.")
|
| 116 |
+
print(output)
|
| 117 |
+
```
|
| 118 |
+
Output:
|
| 119 |
+
```
|
| 120 |
+
{"Premise 1": "If it's wednesday it's cold",
|
| 121 |
+
"Premise 2": "It's cold",
|
| 122 |
+
"Conclusion": "It is Wednesday",
|
| 123 |
+
"Proposition 1": "It is Wednesday",
|
| 124 |
+
"Proposition 2": "It is cold",
|
| 125 |
+
"Type of argument": "affirming the consequent",
|
| 126 |
+
"Negation of Proposition 1": "It is not Wednesday",
|
| 127 |
+
"Negation of Proposition 2": "It is not cold",
|
| 128 |
+
"Validity": true}
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### transformers 🤗
|
| 132 |
+
First make sure to pip install -U transformers, then use the code below replacing the `argument` variable for the argument you want to parse:
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 136 |
+
|
| 137 |
+
model = AutoModelForCausalLM.from_pretrained("cris177/Qwen2-Simple-Arguments",
|
| 138 |
+
device_map="auto",)
|
| 139 |
+
tokenizer = AutoTokenizer.from_pretrained("cris177/Qwen2-Simple-Arguments")
|
| 140 |
+
|
| 141 |
+
argument = "If it's wednesday it's cold, and it's cold, therefore it's wednesday."
|
| 142 |
+
|
| 143 |
+
instruction = 'Based on the following argument, identify the following elements: premises, conclusion, propositions, type of argument, negation of propositions and validity.'
|
| 144 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 145 |
+
|
| 146 |
+
### Instruction:
|
| 147 |
+
{}
|
| 148 |
+
|
| 149 |
+
### Input:
|
| 150 |
+
{}
|
| 151 |
+
|
| 152 |
+
### Response:"""
|
| 153 |
+
prompt = alpaca_prompt.format(instruction, argument)
|
| 154 |
+
input_ids = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 155 |
+
|
| 156 |
+
outputs = model.generate(**input_ids, max_length=1000, num_return_sequences=1)
|
| 157 |
+
print(tokenizer.decode(outputs[0]))
|
| 158 |
+
```
|
| 159 |
+
Output:
|
| 160 |
+
```
|
| 161 |
+
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 162 |
+
|
| 163 |
+
### Instruction:
|
| 164 |
+
Based on the following argument, identify the following elements: premises, conclusion, propositions, type of argument, negation of propositions and validity.
|
| 165 |
+
|
| 166 |
+
### Input:
|
| 167 |
+
If it's wednesday it's cold, and it's cold, therefore it's wednesday.
|
| 168 |
+
|
| 169 |
+
### Response:
|
| 170 |
+
{"Premise 1": "If it's wednesday it's cold",
|
| 171 |
+
"Premise 2": "It's cold",
|
| 172 |
+
"Conclusion": "It is Wednesday",
|
| 173 |
+
"Proposition 1": "It is Wednesday",
|
| 174 |
+
"Proposition 2": "It is cold",
|
| 175 |
+
"Type of argument": "affirming the consequent",
|
| 176 |
+
"Negation of Proposition 1": "It is not Wednesday",
|
| 177 |
+
"Negation of Proposition 2": "It is not cold",
|
| 178 |
+
"Validity": "false"}<|endoftext|>
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
## Training Details
|
| 183 |
+
|
| 184 |
+
### Training Data
|
| 185 |
+
|
| 186 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 187 |
+
|
| 188 |
+
The model was trained on syntethic data, based on the following types of arguments:
|
| 189 |
+
- Modus Ponen
|
| 190 |
+
- Modus Tollen
|
| 191 |
+
- Affirming Consequent
|
| 192 |
+
- Disjunctive Syllogism
|
| 193 |
+
- Denying Antecedent
|
| 194 |
+
- Invalid Conditional Syllogism
|
| 195 |
+
|
| 196 |
+
Each argument was constructed by selecting two random propositions (from a list of 400 propositions that was generated beforehand), choosing a type of argument and combining it all with randomly selected connectors (therefore, since, hence, thus, etc).
|
| 197 |
+
|
| 198 |
+
50k arguments were created to train the model, and 100 to test.
|
| 199 |
+
|
| 200 |
+
### Training Procedure
|
| 201 |
+
|
| 202 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 203 |
+
|
| 204 |
+
#### Preprocessing
|
| 205 |
+
|
| 206 |
+
[More Information Needed]
|
| 207 |
+
We converted the data to the Alpaca chat format before feeding it to the model.
|
| 208 |
+
|
| 209 |
+
#### Training
|
| 210 |
+
|
| 211 |
+
We used unsloth for memory reduced sped up training.
|
| 212 |
+
|
| 213 |
+
We trained for one epoch.
|
| 214 |
+
|
| 215 |
+
Less than 2.5 GB of VRAM were used for training, and it took 2.5 hours.
|
| 216 |
+
|
| 217 |
+
## Evaluation
|
| 218 |
+
|
| 219 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 220 |
+
|
| 221 |
+
The model obtains 100% train and test accuracy on our synthetic dataset.
|