Commit
•
f6c9488
1
Parent(s):
f137547
Update README.md
Browse files
README.md
CHANGED
@@ -3,28 +3,17 @@ library_name: transformers
|
|
3 |
tags:
|
4 |
- unsloth
|
5 |
---
|
|
|
6 |
|
7 |
-
# Model Card for Model ID
|
8 |
|
9 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
## Model Details
|
14 |
|
15 |
### Model Description
|
16 |
|
17 |
<!-- Provide a longer summary of what this model is. -->
|
18 |
|
19 |
-
This is the model
|
|
|
20 |
|
21 |
-
- **Developed by:** [More Information Needed]
|
22 |
-
- **Funded by [optional]:** [More Information Needed]
|
23 |
-
- **Shared by [optional]:** [More Information Needed]
|
24 |
-
- **Model type:** [More Information Needed]
|
25 |
-
- **Language(s) (NLP):** [More Information Needed]
|
26 |
-
- **License:** [More Information Needed]
|
27 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
28 |
|
29 |
### Model Sources [optional]
|
30 |
|
@@ -34,169 +23,174 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
34 |
- **Paper [optional]:** [More Information Needed]
|
35 |
- **Demo [optional]:** [More Information Needed]
|
36 |
|
37 |
-
##
|
38 |
-
|
39 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
40 |
-
|
41 |
-
### Direct Use
|
42 |
-
|
43 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
44 |
-
|
45 |
-
[More Information Needed]
|
46 |
-
|
47 |
-
### Downstream Use [optional]
|
48 |
-
|
49 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
50 |
-
|
51 |
-
[More Information Needed]
|
52 |
-
|
53 |
-
### Out-of-Scope Use
|
54 |
-
|
55 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
56 |
-
|
57 |
-
[More Information Needed]
|
58 |
-
|
59 |
-
## Bias, Risks, and Limitations
|
60 |
-
|
61 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
62 |
-
|
63 |
-
[More Information Needed]
|
64 |
-
|
65 |
-
### Recommendations
|
66 |
-
|
67 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
68 |
-
|
69 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
70 |
-
|
71 |
-
## How to Get Started with the Model
|
72 |
-
|
73 |
-
Use the code below to get started with the model.
|
74 |
-
|
75 |
-
[More Information Needed]
|
76 |
-
|
77 |
-
## Training Details
|
78 |
-
|
79 |
-
### Training Data
|
80 |
-
|
81 |
-
<!-- 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. -->
|
82 |
-
|
83 |
-
[More Information Needed]
|
84 |
-
|
85 |
-
### Training Procedure
|
86 |
-
|
87 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
88 |
-
|
89 |
-
#### Preprocessing [optional]
|
90 |
-
|
91 |
-
[More Information Needed]
|
92 |
-
|
93 |
-
|
94 |
-
#### Training Hyperparameters
|
95 |
-
|
96 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
97 |
-
|
98 |
-
#### Speeds, Sizes, Times [optional]
|
99 |
-
|
100 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
101 |
-
|
102 |
-
[More Information Needed]
|
103 |
-
|
104 |
-
## Evaluation
|
105 |
-
|
106 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
107 |
-
|
108 |
-
### Testing Data, Factors & Metrics
|
109 |
-
|
110 |
-
#### Testing Data
|
111 |
-
|
112 |
-
<!-- This should link to a Dataset Card if possible. -->
|
113 |
-
|
114 |
-
[More Information Needed]
|
115 |
-
|
116 |
-
#### Factors
|
117 |
-
|
118 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
119 |
-
|
120 |
-
[More Information Needed]
|
121 |
-
|
122 |
-
#### Metrics
|
123 |
-
|
124 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
125 |
-
|
126 |
-
[More Information Needed]
|
127 |
-
|
128 |
-
### Results
|
129 |
-
|
130 |
-
[More Information Needed]
|
131 |
-
|
132 |
-
#### Summary
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
|
|
137 |
|
138 |
-
|
|
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
## Environmental Impact
|
143 |
-
|
144 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
145 |
-
|
146 |
-
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).
|
147 |
-
|
148 |
-
- **Hardware Type:** [More Information Needed]
|
149 |
-
- **Hours used:** [More Information Needed]
|
150 |
-
- **Cloud Provider:** [More Information Needed]
|
151 |
-
- **Compute Region:** [More Information Needed]
|
152 |
-
- **Carbon Emitted:** [More Information Needed]
|
153 |
-
|
154 |
-
## Technical Specifications [optional]
|
155 |
-
|
156 |
-
### Model Architecture and Objective
|
157 |
-
|
158 |
-
[More Information Needed]
|
159 |
-
|
160 |
-
### Compute Infrastructure
|
161 |
-
|
162 |
-
[More Information Needed]
|
163 |
|
164 |
-
#### Hardware
|
165 |
|
166 |
-
|
|
|
167 |
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
-
|
|
|
171 |
|
172 |
-
|
|
|
173 |
|
174 |
-
|
|
|
175 |
|
176 |
-
|
177 |
|
178 |
-
[
|
179 |
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
-
[More Information Needed]
|
183 |
|
184 |
-
|
|
|
185 |
|
186 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
187 |
|
188 |
-
[More Information Needed]
|
189 |
|
190 |
-
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
## Model Card Authors [optional]
|
195 |
|
196 |
[More Information Needed]
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
|
|
|
3 |
tags:
|
4 |
- unsloth
|
5 |
---
|
6 |
+
=
|
7 |
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
### Model Description
|
11 |
|
12 |
<!-- Provide a longer summary of what this model is. -->
|
13 |
|
14 |
+
This is the model quantized mistral which is trained using 4bit quantization and Qlora using unsloth library on Academic MCQ based dataset. It takes a Context as input and Generate relevant relevant MCQs. It can further go into specific Subjects like Chemistry, Physics, Biology and General Sunject.
|
15 |
+
You can change instruction to emulate these outputs based on inputs.
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
### Model Sources [optional]
|
19 |
|
|
|
23 |
- **Paper [optional]:** [More Information Needed]
|
24 |
- **Demo [optional]:** [More Information Needed]
|
25 |
|
26 |
+
## Requirements
|
27 |
+
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
!pip install -U xformers --index-url https://download.pytorch.org/whl/cu121
|
30 |
+
!pip install "unsloth[kaggle-new] @ git+https://github.com/unslothai/unsloth.git"
|
31 |
|
32 |
+
import os
|
33 |
+
os.environ["WANDB_DISABLED"] = "true"
|
34 |
|
35 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
37 |
|
38 |
+
### Single Inference
|
39 |
+
```python
|
40 |
|
41 |
+
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
|
42 |
+
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
|
43 |
+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
|
44 |
+
from peft import AutoPeftModelForCausalLM
|
45 |
+
from transformers import AutoTokenizer
|
46 |
+
model_id="DisgustingOzil/Academic-MCQ-Generator"
|
47 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
48 |
+
model_id, # YOUR MODEL YOU USED FOR TRAINING
|
49 |
+
load_in_4bit = load_in_4bit,
|
50 |
+
)
|
51 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
52 |
+
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.
|
53 |
|
54 |
+
### Instruction:
|
55 |
+
{}
|
56 |
|
57 |
+
### Input:
|
58 |
+
{}
|
59 |
|
60 |
+
### Response
|
61 |
+
input2="""Mitosis (/maɪˈtoʊsɪs/) is a part of the cell cycle in which replicated chromosomes are separated into two new nuclei. Cell division by mitosis is an equational division which gives rise to genetically identical cells in which the total number of chromosomes is maintained.[1][2] Mitosis is preceded by the S phase of interphase (during which DNA replication occurs) and is followed by telophase and cytokinesis, which divide the cytoplasm, organelles, and cell membrane of one cell into two new cells containing roughly equal shares of these cellular components.[3] The different stages of mitosis altogether define the mitotic phase (M phase) of a cell cycle—the division of the mother cell into two daughter cells genetically identical to each other.[4]
|
62 |
|
63 |
+
The process of mitosis is divided into stages corresponding to the completion of one set of activities and the start of the next. These stages are preprophase (specific to plant cells), prophase, prometaphase, metaphase, anaphase, and telophase. During mitosis, the chromosomes, which have already duplicated during interphase, condense and attach to spindle fibers that pull one copy of each chromosome to opposite sides of the cell.[5] The result is two genetically identical daughter nuclei. The rest of the cell may then continue to divide by cytokinesis to produce two daughter cells.[6] The different phases of mitosis can be visualized in real time, using live cell imaging.[7]
|
64 |
|
65 |
+
An error in mitosis can result in the production of three or more daughter cells instead of the normal two. This is called tripolar mitosis and multipolar mitosis, respectively. These errors can be the cause of non-viable embryos that fail to implant.[8] Other errors during mitosis can induce mitotic catastrophe, apoptosis (programmed cell death) or cause mutations. Certain types of cancers can arise from such mutations.[9]
|
66 |
|
67 |
+
Mitosis occurs only in eukaryotic cells and varies between organisms.[10] For example, animal cells generally undergo an open mitosis, where the nuclear envelope breaks down before the chromosomes separate, whereas fungal cells generally undergo a closed mitosis, where chromosomes divide within an intact cell nucleus.[11][12] Most animal cells undergo a shape change, known as mitotic cell rounding, to adopt a near spherical morphology at the start of mitosis. Most human cells are produced by mitotic cell division. Important exceptions include the gametes – sperm and egg cells – which are produced by meiosis. Prokaryotes, bacteria and archaea which lack a true nucleus, divide by a different process called binary fission.[13] """
|
68 |
+
inputs = tokenizer(
|
69 |
+
[
|
70 |
+
alpaca_prompt.format(
|
71 |
+
"Generate Biology MCQs from this context", # instruction
|
72 |
+
input2, # input
|
73 |
+
"", # output - leave this blank for generation!
|
74 |
+
)
|
75 |
+
], return_tensors = "pt").to("cuda")
|
76 |
|
|
|
77 |
|
78 |
+
outputs = model.generate(**inputs, max_new_tokens = 200, use_cache = True)
|
79 |
+
result=tokenizer.batch_decode(outputs)
|
80 |
|
|
|
81 |
|
|
|
82 |
|
83 |
+
```
|
84 |
|
85 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
|
|
|
|
86 |
|
87 |
[More Information Needed]
|
88 |
|
89 |
+
### Generating More than One MCQs
|
90 |
+
```python
|
91 |
+
|
92 |
+
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
|
93 |
+
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
|
94 |
+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
|
95 |
+
from peft import AutoPeftModelForCausalLM
|
96 |
+
from transformers import AutoTokenizer
|
97 |
+
model_id="DisgustingOzil/Academic-MCQ-Generator"
|
98 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
99 |
+
model_id, # YOUR MODEL YOU USED FOR TRAINING
|
100 |
+
load_in_4bit = load_in_4bit,
|
101 |
+
)
|
102 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
103 |
+
input2="""Mitosis (/maɪˈtoʊsɪs/) is a part of the cell cycle in which replicated chromosomes are separated into two new nuclei. Cell division by mitosis is an equational division which gives rise to genetically identical cells in which the total number of chromosomes is maintained.[1][2] Mitosis is preceded by the S phase of interphase (during which DNA replication occurs) and is followed by telophase and cytokinesis, which divide the cytoplasm, organelles, and cell membrane of one cell into two new cells containing roughly equal shares of these cellular components.[3] The different stages of mitosis altogether define the mitotic phase (M phase) of a cell cycle—the division of the mother cell into two daughter cells genetically identical to each other.[4]
|
104 |
+
|
105 |
+
The process of mitosis is divided into stages corresponding to the completion of one set of activities and the start of the next. These stages are preprophase (specific to plant cells), prophase, prometaphase, metaphase, anaphase, and telophase. During mitosis, the chromosomes, which have already duplicated during interphase, condense and attach to spindle fibers that pull one copy of each chromosome to opposite sides of the cell.[5] The result is two genetically identical daughter nuclei. The rest of the cell may then continue to divide by cytokinesis to produce two daughter cells.[6] The different phases of mitosis can be visualized in real time, using live cell imaging.[7]
|
106 |
+
|
107 |
+
An error in mitosis can result in the production of three or more daughter cells instead of the normal two. This is called tripolar mitosis and multipolar mitosis, respectively. These errors can be the cause of non-viable embryos that fail to implant.[8] Other errors during mitosis can induce mitotic catastrophe, apoptosis (programmed cell death) or cause mutations. Certain types of cancers can arise from such mutations.[9]
|
108 |
+
|
109 |
+
Mitosis occurs only in eukaryotic cells and varies between organisms.[10] For example, animal cells generally undergo an open mitosis, where the nuclear envelope breaks down before the chromosomes separate, whereas fungal cells generally undergo a closed mitosis, where chromosomes divide within an intact cell nucleus.[11][12] Most animal cells undergo a shape change, known as mitotic cell rounding, to adopt a near spherical morphology at the start of mitosis. Most human cells are produced by mitotic cell division. Important exceptions include the gametes – sperm and egg cells – which are produced by meiosis. Prokaryotes, bacteria and archaea which lack a true nucleus, divide by a different process called binary fission.[13] """
|
110 |
+
def partition(total_text):
|
111 |
+
|
112 |
+
# Split the text into words
|
113 |
+
words = total_text.split()
|
114 |
+
total_words = len(words)
|
115 |
+
print(total_words)
|
116 |
+
# Determine the number of words per partition, aiming for 5 equal parts
|
117 |
+
words_per_partition = total_words // 5
|
118 |
+
partitions = []
|
119 |
+
|
120 |
+
# Create partitions
|
121 |
+
for i in range(0, total_words, words_per_partition):
|
122 |
+
partition = " ".join(words[i:i+words_per_partition])
|
123 |
+
if len(partition)>100:
|
124 |
+
partitions.append(partition)
|
125 |
+
return partitions
|
126 |
+
partitions=partition(input2)
|
127 |
+
import re
|
128 |
+
|
129 |
+
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.
|
130 |
+
|
131 |
+
### Instruction:
|
132 |
+
{}
|
133 |
+
|
134 |
+
### Input:
|
135 |
+
{}
|
136 |
+
|
137 |
+
### Response:
|
138 |
+
{}"""
|
139 |
+
pattern = r'<question>(.*?)</question>.*?<answer>(.*?)</answer>'
|
140 |
+
mcq_pattern = r'<question>(.*?)</question>.*?<answer>(.*?)</answer>.*?<distractor>(.*?)</distractor>'
|
141 |
+
# for part in partitions:
|
142 |
+
for part in partitions:
|
143 |
+
inputs = tokenizer(
|
144 |
+
[
|
145 |
+
alpaca_prompt.format(
|
146 |
+
"Generate Biology MCQs from this context", # instruction
|
147 |
+
part, # input
|
148 |
+
"", # output - leave this blank for generation!
|
149 |
+
)
|
150 |
+
], return_tensors = "pt").to("cuda")
|
151 |
+
|
152 |
+
|
153 |
+
outputs = model.generate(**inputs, max_new_tokens = 200, use_cache = True)
|
154 |
+
result=tokenizer.batch_decode(outputs)
|
155 |
+
matches = re.findall(mcq_pattern, result[0], re.DOTALL)
|
156 |
+
|
157 |
+
question = matches[0][0].strip()
|
158 |
+
correct_answer = matches[0][1].strip()
|
159 |
+
distractors = [d.strip() for d in matches[0][2].split('<d>') if d.strip()]
|
160 |
+
print(question)
|
161 |
+
print(correct_answer)
|
162 |
+
print("Distractors:", distractors)
|
163 |
+
|
164 |
+
outputs = model.generate(**inputs, max_new_tokens = 200, use_cache = True,temperature=0.9,
|
165 |
+
top_k=50,
|
166 |
+
top_p=0.95,
|
167 |
+
no_repeat_ngram_size=2,)
|
168 |
+
result=tokenizer.batch_decode(outputs)
|
169 |
+
matches=None
|
170 |
+
|
171 |
+
matches = re.findall(mcq_pattern, result[0], re.DOTALL)
|
172 |
+
if len(matches)==0:
|
173 |
+
matches = re.findall(pattern, result[0], re.DOTALL)
|
174 |
+
print(matches)
|
175 |
+
question = matches[0][0].strip()
|
176 |
+
correct_answer = matches[0][1].strip()
|
177 |
+
print("Question:", question)
|
178 |
+
print("Correct Answer:", correct_answer)
|
179 |
+
else:
|
180 |
+
print(matches)
|
181 |
+
question = matches[0][0].strip()
|
182 |
+
correct_answer = matches[0][1].strip()
|
183 |
+
distractors = [d.strip() for d in matches[0][2].split('<d>') if d.strip()]
|
184 |
+
print("Question:", question)
|
185 |
+
print("Correct Answer:", correct_answer)
|
186 |
+
print("Distractors:", distractors)
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
|
191 |
+
|
192 |
+
|
193 |
+
|
194 |
+
```
|
195 |
|
196 |
|