Spaces:
Build error
Build error
Init
Browse files- .gitignore +3 -0
- app.py +25 -0
- ch-sent-check-model/config.json +31 -0
- ch-sent-check-model/pytorch_model.bin +3 -0
- ch-sent-check-model/special_tokens_map.json +1 -0
- ch-sent-check-model/tokenizer.json +0 -0
- ch-sent-check-model/tokenizer_config.json +1 -0
- ch-sent-check-model/vocab.txt +0 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
pyproject.toml
|
3 |
+
flagged/
|
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BertTokenizerFast, BertForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
model = BertForSequenceClassification.from_pretrained('./ch-sent-check-model')
|
6 |
+
tokenizer = BertTokenizerFast.from_pretrained('./ch-sent-check-model')
|
7 |
+
|
8 |
+
def judge(sentence):
|
9 |
+
input_ids = tokenizer(sentence,return_tensors='pt')['input_ids']
|
10 |
+
out = model(input_ids)
|
11 |
+
logits = out.logits
|
12 |
+
pred = torch.argmax(logits,dim=-1).item()
|
13 |
+
pred_text = 'Incorrect' if pred == 0 else 'Correct'
|
14 |
+
return pred_text
|
15 |
+
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=judge,
|
18 |
+
inputs=gr.Textbox(
|
19 |
+
label="Initial text",
|
20 |
+
lines=1,
|
21 |
+
value="請注意用字的鄭確性",
|
22 |
+
),
|
23 |
+
outputs="text"
|
24 |
+
)
|
25 |
+
iface.launch()
|
ch-sent-check-model/config.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "bert-base-chinese",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"directionality": "bidi",
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 3072,
|
14 |
+
"layer_norm_eps": 1e-12,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"model_type": "bert",
|
17 |
+
"num_attention_heads": 12,
|
18 |
+
"num_hidden_layers": 12,
|
19 |
+
"pad_token_id": 0,
|
20 |
+
"pooler_fc_size": 768,
|
21 |
+
"pooler_num_attention_heads": 12,
|
22 |
+
"pooler_num_fc_layers": 3,
|
23 |
+
"pooler_size_per_head": 128,
|
24 |
+
"pooler_type": "first_token_transform",
|
25 |
+
"position_embedding_type": "absolute",
|
26 |
+
"torch_dtype": "float32",
|
27 |
+
"transformers_version": "4.18.0",
|
28 |
+
"type_vocab_size": 2,
|
29 |
+
"use_cache": true,
|
30 |
+
"vocab_size": 21128
|
31 |
+
}
|
ch-sent-check-model/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e8b7cb387f207d502b34d79ae10d12e7e7223c0078a90300002400044bc437fb
|
3 |
+
size 409144941
|
ch-sent-check-model/special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
ch-sent-check-model/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
ch-sent-check-model/tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "bert-base-chinese", "tokenizer_class": "BertTokenizer"}
|
ch-sent-check-model/vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.*.*
|
2 |
+
torch==1.12.*
|
3 |
+
gradio
|