etweedy commited on
Commit
9ff73a6
1 Parent(s): 111b567

Upload 7 files

Browse files
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import transformers
3
+ from transformers import DistilBertTokenizerFast
4
+ from transformers import DistilBertForSequenceClassification
5
+ import gradio as gr
6
+
7
+ # Load the pre-trained tokenizer
8
+ tokenizer = DistilBertTokenizerFast.from_pretrained('./model_save/',local_files_only=True)
9
+
10
+ # Load the pre-trained DilBERT model
11
+ model = DistilBertForSequenceClassification.from_pretrained('./model_save/',local_files_only=True)
12
+ model.eval()
13
+
14
+ # Define a predict function
15
+ def predict(text):
16
+ encoding=tokenizer(text,return_tensors='pt')
17
+ input_ids, attention_mask = encoding['input_ids'],encoding['attention_mask']
18
+ outputs = model(input_ids,attention_mask=attention_mask)
19
+ logits = outputs['logits']
20
+ pred_label = torch.argmax(logits,1)[0]
21
+ return 'Positive' if pred_label > 0.5 else 'Negative'
22
+
23
+ # Initialize the Gradio interface
24
+ title = "Write a movie review"
25
+ description = "Enter a review for a movie you've seen. This tool will try to guess whether your review is positive or negative."
26
+ gr.Interface(fn=predict,
27
+ inputs="text",
28
+ outputs="label",
29
+ title = title,
30
+ description = description,
31
+ ).launch()
model_save/config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "distilbert-base-uncased",
3
+ "activation": "gelu",
4
+ "architectures": [
5
+ "DistilBertForSequenceClassification"
6
+ ],
7
+ "attention_dropout": 0.1,
8
+ "dim": 768,
9
+ "dropout": 0.1,
10
+ "hidden_dim": 3072,
11
+ "initializer_range": 0.02,
12
+ "max_position_embeddings": 512,
13
+ "model_type": "distilbert",
14
+ "n_heads": 12,
15
+ "n_layers": 6,
16
+ "pad_token_id": 0,
17
+ "problem_type": "single_label_classification",
18
+ "qa_dropout": 0.1,
19
+ "seq_classif_dropout": 0.2,
20
+ "sinusoidal_pos_embds": false,
21
+ "tie_weights_": true,
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.20.1",
24
+ "vocab_size": 30522
25
+ }
model_save/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a619cd8c20b321c9442a77f080497fbc1d94e9340eab738fa80fd7b280086ea
3
+ size 267854321
model_save/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
+ }
model_save/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
model_save/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": "distilbert-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": "DistilBertTokenizer",
13
+ "unk_token": "[UNK]"
14
+ }
model_save/vocab.txt ADDED
The diff for this file is too large to render. See raw diff