JacobLinCool commited on
Commit
edc139b
·
1 Parent(s): 7226b69

fix: gguf dequantize

Browse files
model/mistral_7b_ielts_evaluator.py CHANGED
@@ -1,32 +1,66 @@
1
  from typing import *
2
  import torch
3
- import numpy as np
4
- from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
  import spaces
6
 
7
  model_name = "chillies/mistral-7b-ielts-evaluator-q4"
8
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
- tokenizer = AutoTokenizer.from_pretrained(model_name)
 
 
10
 
 
11
 
12
- @spaces.GPU()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  @torch.no_grad()
14
  def grade_mistral_7b_ielts_evaluator(question: str, answer: str) -> Tuple[float, str]:
15
- text = f"{question} {answer}"
16
 
17
- inputs = tokenizer(
18
- text,
19
- return_tensors="pt",
20
- padding=True,
21
- truncation=True,
22
- )
23
 
24
- outputs = model(**inputs)
25
- score = outputs.logits.argmax(dim=-1).item()
26
- print(score)
27
 
28
- overall_score = float(score)
 
29
 
30
- comment = ""
 
31
 
32
- return overall_score, comment
 
1
  from typing import *
2
  import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
4
  import spaces
5
 
6
  model_name = "chillies/mistral-7b-ielts-evaluator-q4"
7
+ file_name = "GUFF-ielts-fighter-unsloth.Q4_K_M.gguf"
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, gguf_file=file_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name, gguf_file=file_name)
10
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
 
12
+ system = """In this task, you are required to evaluate an IELTS Writing Task 2 essay. Consider the following four criteria and provide a detailed assessment for each, along with a suggested band score:
13
 
14
+ ## Task Achievement:
15
+ - Evaluate how well the candidate has addressed the given task.
16
+ - Assess the clarity and coherence of the response in presenting ideas.
17
+ - Identify if the candidate has fully covered all parts of the task and supported arguments appropriately.
18
+ - Suggested Band Score (Task Achievement): [Insert Score]
19
+
20
+ ## Coherence and Cohesion:
21
+ - Assess the overall organization and structure of the essay.
22
+ - Evaluate the use of linking devices to connect ideas and paragraphs.
23
+ - Identify if there is a logical flow of information.
24
+ - Suggested Band Score (Coherence and Cohesion): [Insert Score]
25
+
26
+ ## Lexical Resource (Vocabulary):
27
+ - Examine the range and accuracy of vocabulary used in the essay.
28
+ - Point out specific mistakes in vocabulary, such as inaccuracies or overuse of certain words and Suggest modified versions or alternatives for the identified mistakes. [list of mistakes and rectify]
29
+ - Assess the appropriateness of vocabulary for the given context.
30
+ - Suggested Band Score (Lexical Resource): [Insert Score]
31
+
32
+ ## Grammatical Range and Accuracy:
33
+ - Evaluate the variety and complexity of sentence structures.
34
+ - Point out specific grammatical errors, such as incorrect verb forms or sentence construction and Suggest modified versions or corrections for the identified mistakes. [list of mistakes and rectify]
35
+ - Examine the use of punctuation and sentence formation.
36
+ - Suggested Band Score (Grammatical Range and Accuracy): [Insert Score]
37
+
38
+ ## Overall Band Score:
39
+
40
+ - Provide an overall band score for the essay, considering the holistic performance across all criteria.
41
+ - Consider the synergy of the essay in meeting the task requirements cohesively.
42
+ - Suggested Overall Band Score: [Insert Score]
43
+
44
+ ## Feedback and Additional Comments:
45
+ - Provide constructive feedback highlighting specific strengths and areas for improvement.
46
+ - Suggest strategies for enhancement in weaker areas."""
47
+
48
+
49
+ @spaces.GPU(duration=120)
50
  @torch.no_grad()
51
  def grade_mistral_7b_ielts_evaluator(question: str, answer: str) -> Tuple[float, str]:
52
+ text = f"""{system}
53
 
54
+ ## Prompt:
55
+ {question}
 
 
 
 
56
 
57
+ ## Essay:
58
+ {answer}
 
59
 
60
+ ## Evaluation:
61
+ """
62
 
63
+ outputs = pipe(text)
64
+ overall_score = float(0.0)
65
 
66
+ return overall_score, outputs
requirements.txt CHANGED
@@ -1,6 +1,9 @@
1
  torch
2
- transformers
 
3
  accelerate
4
  spaces
5
  gradio
6
  numpy
 
 
 
1
  torch
2
+ # transformers (wait for 4.44.0)
3
+ git+https://github.com/huggingface/transformers
4
  accelerate
5
  spaces
6
  gradio
7
  numpy
8
+ gguf
9
+ sentencepiece