stefanoscotta commited on
Commit
7e97350
1 Parent(s): 48b0eea

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -3
README.md CHANGED
@@ -1,3 +1,151 @@
1
- ---
2
- license: unknown
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: unknown
3
+ ---
4
+
5
+ # Model Card raicrits/Llama3_ChangeOfTopic
6
+
7
+ <!-- Provide a quick summary of what the model is/does. -->
8
+
9
+ LoRa adapters for [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) obtained through a finetuning process (using LoRA technique) aimed at making the model capable of detecting
10
+ a change of topic in a given text.
11
+
12
+
13
+ ### Model Description
14
+
15
+
16
+ The model resulting from the application of the adapters in this repository to the base model [meta-llama/MMeta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) is optimized to perform the
17
+ specific task of detecting a change of topic in a given text. Given a text the model answers with "1" in the case that it detects a change of topic and "0" otherwise.
18
+ The training has been done using the chapters in the Youtube videos contained in the train split of the dataset [raicrits/YouTube_RAI_dataset](https://huggingface.co/meta-llama/raicrits/YouTube_RAI_dataset).
19
+ Because of the finetuning process it is important to respect the prompt template in order to get good results.
20
+
21
+
22
+ - **Developed by:** Stefano Scotta ([email protected])
23
+ - **Model type:** LLM finetuned on the specific task of assign tags to news articles
24
+ - **Language(s) (NLP):** Italian
25
+ - **License:** unknown
26
+ - **Finetuned from model [optional]:** [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct)
27
+
28
+
29
+ ## Uses
30
+
31
+ The model can be used to check if in a given text occurs a chagne of topic or not.
32
+
33
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
34
+
35
+
36
+ ## Bias, Risks, and Limitations
37
+
38
+ As any other LLM it is possible that the model generates content which does not correspond to the reality as well as wrong, biased, offensive and inappropriate answers.
39
+
40
+
41
+ ## How to Get Started with the Model
42
+
43
+ Use the code below to get started with the model.
44
+
45
+ **Usage:**
46
+ Use the code below to get started with the model.
47
+ ``` python
48
+ import os
49
+ import torch
50
+ import sys
51
+ from transformers import LlamaForCausalLM, AutoTokenizer
52
+ from peft import PeftModel
53
+
54
+ model_id = "meta-llama/Meta-Llama-3-8B"
55
+ lora_id = "raicrits/Llama3_ChangeOfTopic"
56
+
57
+ quantization_config = BitsAndBytesConfig(
58
+ load_in_8bit=True)
59
+
60
+ base_model = AutoModelForCausalLM.from_pretrained(model_id,
61
+ quantization_config=quantization_config,
62
+ device_map=device)
63
+ model = PeftModel.from_pretrained(base_model, lora_id)
64
+
65
+
66
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
67
+ tokenizer.pad_token = tokenizer.eos_token
68
+ tokenizer.padding_side = "right"
69
+
70
+ terminators = [
71
+ tokenizer.eos_token_id,
72
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
73
+ ]
74
+
75
+ messages = [
76
+ {"role": "system", "content": "You are an AI assistant able to detect change of topics in given texts."},
77
+ {"role": "user", "content": f"""Analyze the following text written in italian and in case you detect a change of topic answer just with "1", otherwise, if the topic remains the same within all the given text answer just "0". do not add further text.
78
+
79
+ Text: {'<text>'}
80
+ ]
81
+
82
+ input_ids = tokenizer.apply_chat_template(
83
+ messages,
84
+ add_generation_prompt=True,
85
+ return_tensors="pt").to(model.device)
86
+
87
+ with torch.no_grad():
88
+ outputs = model.generate(
89
+ input_ids,
90
+ max_new_tokens=1,
91
+ eos_token_id=terminators,
92
+ do_sample=True,
93
+ temperature=0.2
94
+ )
95
+ response = outputs[0][input_ids.shape[-1]:]
96
+ print(tokenizer.decode(response, skip_special_tokens=False))
97
+ ```
98
+
99
+ ## Training Details
100
+
101
+ ### Training Data
102
+
103
+ Chapters in the Youtube videos contained in the train split of the dataset [raicrits/YouTube_RAI_dataset](https://huggingface.co/meta-llama/raicrits/YouTube_RAI_dataset)
104
+
105
+ ### Training Procedure
106
+
107
+ The fine-tuning procedure was done using [LoRA](https://arxiv.org/abs/2106.09685) approach.
108
+
109
+ **Training setting:**
110
+ - train epochs=1,
111
+
112
+ - learning_rate=2e-05
113
+
114
+ - mixed precision training: int8
115
+
116
+
117
+ **LoRA configuration:**
118
+ - r= 8
119
+
120
+ - lora_alpha=16
121
+
122
+ - target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]
123
+
124
+ - lora_dropout=0.1
125
+
126
+ - bias="none"
127
+
128
+ - task_type=CAUSAL_LM
129
+
130
+
131
+
132
+ [More Information Needed]
133
+
134
+ ## Environmental Impact
135
+
136
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
137
+
138
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
139
+
140
+ - **Hardware Type:** 1 NVIDIA A100/40Gb
141
+ - **Hours used:** 45
142
+ - **Cloud Provider:** Private Infrastructure
143
+ - **Carbon Emitted:** 4.86kg eq. CO2
144
+
145
+ ## Model Card Authors
146
+
147
+ Stefano Scotta ([email protected])
148
+
149
+ ## Model Card Contact
150
+
151