armaniii commited on
Commit
52c7cc4
·
verified ·
1 Parent(s): 5d7be85

Add complete model card: pipeline overview, adapter/full-model explanation, download and usage instructions with exact prompt formats and label mappings

Browse files
Files changed (1) hide show
  1. README.md +126 -177
README.md CHANGED
@@ -1,199 +1,148 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
 
 
 
 
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
 
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
 
 
 
 
 
 
43
 
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- 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. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- - **Hardware Type:** [More Information Needed]
146
- - **Hours used:** [More Information Needed]
147
- - **Cloud Provider:** [More Information Needed]
148
- - **Compute Region:** [More Information Needed]
149
- - **Carbon Emitted:** [More Information Needed]
150
-
151
- ## Technical Specifications [optional]
152
-
153
- ### Model Architecture and Objective
154
-
155
- [More Information Needed]
156
-
157
- ### Compute Infrastructure
158
-
159
- [More Information Needed]
160
-
161
- #### Hardware
162
-
163
- [More Information Needed]
164
-
165
- #### Software
166
-
167
- [More Information Needed]
168
-
169
- ## Citation [optional]
170
-
171
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
172
-
173
- **BibTeX:**
174
-
175
- [More Information Needed]
176
-
177
- **APA:**
178
-
179
- [More Information Needed]
180
-
181
- ## Glossary [optional]
182
-
183
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
184
-
185
- [More Information Needed]
186
-
187
- ## More Information [optional]
188
- (https://arxiv.org/abs/2405.00828)
189
- [More Information Needed]
190
-
191
- ## Model Card Authors [optional]
192
-
193
- [More Information Needed]
194
-
195
- ## Model Card Contact
196
-
197
- [More Information Needed]
198
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: transformers
3
+ base_model: meta-llama/Meta-Llama-3-8B
4
+ license: llama3
5
+ language:
6
+ - en
7
+ pipeline_tag: text-generation
8
+ tags:
9
+ - argument-mining
10
+ - topic-extraction
11
+ - claim-extraction
12
+ - computational-social-science
13
+ - llama
14
+ - wiba
15
  ---
16
 
17
+ # WIBA Claim Topic Extraction (Llama-3-8B, full model)
18
+
19
+ **Topic extraction** model: given an argumentative sentence or passage, it generates the **topic being argued** (a short phrase naming the person, place, thing, entity, or idea at issue), or **`No Topic`** if the text is not an argument. The topic may be explicit in the text or implicit and inferred from context.
20
+
21
+ This is **Stage 2** of the [WIBA (What Is Being Argued?)](https://arxiv.org/abs/2405.00828) argument mining pipeline:
22
+
23
+ | Stage | Task | Model | Type |
24
+ |---|---|---|---|
25
+ | 1. Detect | Is this text an argument? | [armaniii/llama-3-8b-argument-detection](https://huggingface.co/armaniii/llama-3-8b-argument-detection) | LoRA adapter (sequence classification, 2 labels) |
26
+ | **2. Extract** | What topic is being argued? | **this repo** | Full fine-tuned causal LM |
27
+ | 3. Stance | What position does it take on the topic? | [armaniii/llama-stance-classification](https://huggingface.co/armaniii/llama-stance-classification) | LoRA adapter (sequence classification, 3 labels) |
28
+
29
+ - 📄 Paper: [WIBA: What Is Being Argued? A Comprehensive Approach to Argument Mining](https://arxiv.org/abs/2405.00828)
30
+ - 💻 Code: [github.com/Armaniii/WIBA](https://github.com/Armaniii/WIBA)
31
+ - 🌐 Platform: [wiba.dev](https://wiba.dev)
32
 
33
+ ## What this repo contains (full model, not an adapter)
34
 
35
+ Unlike the detect and stance stages, this repo is a **complete, self-contained fine-tuned model** (`LlamaForCausalLM`, ~16 GB of float16 safetensors in two shards). You do **not** need to download the base Llama-3 weights or merge any adapter — `from_pretrained` on this repo alone is enough.
36
 
37
+ | File | Purpose |
38
+ |---|---|
39
+ | `model-0000*-of-00002.safetensors` + index | Full fine-tuned weights (float16) |
40
+ | `config.json` | Model config — **note: ships with a bitsandbytes 4-bit (nf4) `quantization_config` baked in** (see below) |
41
+ | `generation_config.json` | Default generation settings |
42
+ | `tokenizer.json`, `tokenizer_config.json`, `special_tokens_map.json` | Llama-3 tokenizer |
43
+
44
+ > **Quantization note:** because `config.json` includes a `quantization_config`, `from_pretrained` will automatically load the model 4-bit quantized (~6 GB VRAM) when `bitsandbytes` is installed — this matches the production WIBA deployment. To load in full fp16 instead, strip the quantization config (snippet below).
45
 
46
+ ## Quickstart
47
 
48
+ ```bash
49
+ pip install torch transformers accelerate bitsandbytes
50
+ ```
51
 
52
+ ```python
53
+ import torch
54
+ from transformers import AutoTokenizer, AutoModelForCausalLM
55
 
56
+ REPO = "armaniii/llama-3-8b-claim-topic-extraction"
57
 
58
+ tokenizer = AutoTokenizer.from_pretrained(REPO, use_fast=False)
59
+ tokenizer.pad_token_id = tokenizer.eos_token_id
60
+ tokenizer.padding_side = "left"
 
 
 
 
61
 
62
+ # Loads 4-bit (nf4) automatically via the config's quantization_config (~6 GB VRAM)
63
+ model = AutoModelForCausalLM.from_pretrained(
64
+ REPO, torch_dtype=torch.float16, device_map="auto", low_cpu_mem_usage=True
65
+ )
66
+ model.eval()
67
+ ```
68
 
69
+ To load **full fp16** (~16 GB VRAM) instead of 4-bit:
70
 
71
+ ```python
72
+ from transformers import AutoConfig
 
73
 
74
+ config = AutoConfig.from_pretrained(REPO)
75
+ if hasattr(config, "quantization_config"):
76
+ delattr(config, "quantization_config")
77
+ model = AutoModelForCausalLM.from_pretrained(
78
+ REPO, config=config, torch_dtype=torch.float16, device_map="auto"
79
+ )
80
+ ```
81
 
82
+ ### Prompt format (must match training)
83
 
84
+ The model expects the Llama-3 chat header format with the WIBA topic-extraction system prompt, and the generation cut off after a few tokens (topics are short):
85
 
86
+ ```python
87
+ SYSTEM_PROMPT = """You are a helpful assistant that is specialized in a single task. If the sentence provided is an argument, decide what the topic being argued is using the rules and steps below.
88
+ Rules:
89
+ 1. An argument is a sentence that must contain a claim AND AT LEAST ONE premise(i.e evidence) supporting that assertion or claim.
90
+ 2. A claim is the position being taken in the argument.
91
+ 3. A premise is a statement that provides evidence to support the claim.
92
+ 4. In order for a sentence to be an argument it must contain a claim AND at least one premise.
93
+ 5. If the sentence does not contain a claim AND does not provide any premises to support the claim, then it is a non-argument.
94
+ 6. If the sentence provided is an argument, then there must be a single topic being argued that is regarding a person, place, thing, entity, or abstract idea. The topic being argued may be explicitly stated OR it may be implicit and must be inferred from the context of the argument.
95
+ 7. If the sentence provided is a non-argument, then there is no topic being argued.
96
 
97
+ Steps:
98
+ 1. Decide if the sentence provided is an argument or non-argument using the Rules provided.
99
+ 2. If the sentence is an argument, output only the topic being argued and your task is finished.
100
+ 3. If the sentence is a non-argument, only output: No Topic and your task is finished.
101
+ 4. If the sentence provided is a non-argument, then there is no topic being argued and you should only output: No Topic
102
+ 5. Let us think through the problem step by step carefully following all the rules outlined."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ def extract_topic(text: str) -> str:
105
+ prompt = (
106
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n"
107
+ + SYSTEM_PROMPT
108
+ + "<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"
109
+ + text
110
+ + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
111
+ )
112
+ enc = tokenizer(prompt, return_tensors="pt").to(model.device)
113
+ with torch.no_grad():
114
+ out = model.generate(**enc, max_new_tokens=8, pad_token_id=128009)
115
+ return tokenizer.decode(out[0, enc.input_ids.shape[1]:], skip_special_tokens=True).strip()
116
 
117
+ print(extract_topic("We must act on climate change because temperatures are rising."))
118
+ # -> a topic phrase, e.g. "Climate change"
119
+ print(extract_topic("The weather is nice today."))
120
+ # -> "No Topic"
121
+ ```
122
+
123
+ The original implementation uses the equivalent `pipeline("text-generation", ..., max_new_tokens=8, pad_token_id=128009)` and takes the text after the final `assistant<|end_header_id|>\n\n` marker — the function above does the same thing with `generate`.
124
+
125
+ ### Output
126
+
127
+ - An argumentative input → a short topic phrase (e.g. `Climate change`, `Gun control`)
128
+ - A non-argument input → the literal string `No Topic`
129
+
130
+ ## How it's used in the WIBA implementation
131
+
132
+ In the WIBA serving code, this model backs the `/api/extract` endpoint at [wiba.dev](https://wiba.dev). Texts that Stage 1 classified as `Argument` are passed here to name the topic; the (text, topic) pair is then passed to Stage 3 ([stance classification](https://huggingface.co/armaniii/llama-stance-classification)) to determine whether the argument is in favor of or against that topic. For batch processing the implementation streams prompts through the pipeline with `batch_size=2` and left-padding.
133
+
134
+ ## Citation
135
+
136
+ ```bibtex
137
+ @article{irani2024wiba,
138
+ title={WIBA: What Is Being Argued? A Comprehensive Approach to Argument Mining},
139
+ author={Irani, Arman and Park, Ju Yeon and Esterling, Kevin and Faloutsos, Michalis},
140
+ journal={arXiv preprint arXiv:2405.00828},
141
+ year={2024}
142
+ }
143
+ ```
144
+
145
+ ## Notes
146
+
147
+ - Fine-tuned from `meta-llama/Meta-Llama-3-8B` (Llama 3 license applies). The weights here are already fine-tuned; the base model is not required.
148
+ - Internal fine-tune lineage: `llama_cte_v3`.