Spaces:
Runtime error
Runtime error
khaled5321
commited on
Commit
•
366bd77
1
Parent(s):
de42533
Add application file
Browse files- app.py +53 -0
- model/config.json +37 -0
- model/pytorch_model.bin +3 -0
- requirements.txt +0 -0
- tokenizer/special_tokens_map.json +7 -0
- tokenizer/tokenizer.json +0 -0
- tokenizer/tokenizer_config.json +14 -0
- tokenizer/vocab.txt +0 -0
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
5 |
+
|
6 |
+
|
7 |
+
labels = {
|
8 |
+
0 : "Incorrect",
|
9 |
+
1 : "Partialy correct/Incomplete",
|
10 |
+
2 : "correct"
|
11 |
+
}
|
12 |
+
|
13 |
+
print('currently loading model')
|
14 |
+
model = AutoModelForSequenceClassification.from_pretrained("./model")
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("./tokenizer")
|
16 |
+
print('model loaded successfully')
|
17 |
+
|
18 |
+
def grade(model_answer, student_answer):
|
19 |
+
inputs = tokenizer(model_answer, student_answer, padding="max_length", truncation=True, return_tensors="pt")
|
20 |
+
|
21 |
+
with torch.no_grad():
|
22 |
+
logits = model(**inputs).logits
|
23 |
+
|
24 |
+
preds = torch.nn.functional.softmax(logits, dim=1)
|
25 |
+
preds = np.concatenate(preds.numpy()).ravel().tolist()
|
26 |
+
print(preds)
|
27 |
+
return {l:p for p, l in zip(preds, labels.values())}
|
28 |
+
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=grade,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(lines=2, placeholder="Model answer here"),
|
33 |
+
gr.Textbox(lines=2, placeholder="Student answer here")
|
34 |
+
],
|
35 |
+
outputs="label",
|
36 |
+
title="Grading short answer questions",
|
37 |
+
examples=[
|
38 |
+
[
|
39 |
+
"A prototype is used to simulate the behavior of portions of the desired software product",
|
40 |
+
"a prototype is used to simulate the behavior of a portion of the desired software product"
|
41 |
+
],
|
42 |
+
[
|
43 |
+
"A variable in programming is a location in memory that can be used to store a value",
|
44 |
+
"no answer"
|
45 |
+
],
|
46 |
+
[
|
47 |
+
"A computer system consists of a CPU, Memory, Input, and output devices.",
|
48 |
+
"a CPU only"
|
49 |
+
],
|
50 |
+
],
|
51 |
+
)
|
52 |
+
|
53 |
+
demo.launch()
|
model/config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "bert-base-uncased",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"gradient_checkpointing": false,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"id2label": {
|
13 |
+
"0": "LABEL_0",
|
14 |
+
"1": "LABEL_1",
|
15 |
+
"2": "LABEL_2"
|
16 |
+
},
|
17 |
+
"initializer_range": 0.02,
|
18 |
+
"intermediate_size": 3072,
|
19 |
+
"label2id": {
|
20 |
+
"LABEL_0": 0,
|
21 |
+
"LABEL_1": 1,
|
22 |
+
"LABEL_2": 2
|
23 |
+
},
|
24 |
+
"layer_norm_eps": 1e-12,
|
25 |
+
"max_position_embeddings": 512,
|
26 |
+
"model_type": "bert",
|
27 |
+
"num_attention_heads": 12,
|
28 |
+
"num_hidden_layers": 12,
|
29 |
+
"pad_token_id": 0,
|
30 |
+
"position_embedding_type": "absolute",
|
31 |
+
"problem_type": "single_label_classification",
|
32 |
+
"torch_dtype": "float32",
|
33 |
+
"transformers_version": "4.26.1",
|
34 |
+
"type_vocab_size": 2,
|
35 |
+
"use_cache": true,
|
36 |
+
"vocab_size": 30522
|
37 |
+
}
|
model/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a1eb7422279f59247275a5dd509c1463cc71e82922887e26aee34b4d32bdfbb5
|
3 |
+
size 438008181
|
requirements.txt
ADDED
Binary file (2.38 kB). View file
|
|
tokenizer/special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer/tokenizer_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"do_lower_case": true,
|
4 |
+
"mask_token": "[MASK]",
|
5 |
+
"model_max_length": 512,
|
6 |
+
"name_or_path": "bert-base-uncased",
|
7 |
+
"pad_token": "[PAD]",
|
8 |
+
"sep_token": "[SEP]",
|
9 |
+
"special_tokens_map_file": null,
|
10 |
+
"strip_accents": null,
|
11 |
+
"tokenize_chinese_chars": true,
|
12 |
+
"tokenizer_class": "BertTokenizer",
|
13 |
+
"unk_token": "[UNK]"
|
14 |
+
}
|
tokenizer/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|