Spaces:
Runtime error
Runtime error
ben-epstein
commited on
Commit
•
4bad7b8
1
Parent(s):
c417e30
small demo
Browse files- README.md +5 -0
- app.py +53 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -11,3 +11,8 @@ license: apache-2.0
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
14 |
+
|
15 |
+
## Simple app showcasing the [spacy-to-hf](https://github.com/Ben-Epstein/spacy-to-hf) repo
|
16 |
+
|
17 |
+
Add in your NER Span data and get back a huggingface dataset ready
|
18 |
+
for fine-tuning Token Classification!
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from spacy_to_hf import spacy_to_hf
|
3 |
+
import os
|
4 |
+
import spacy
|
5 |
+
from datasets import Dataset
|
6 |
+
import json
|
7 |
+
from json import JSONDecodeError
|
8 |
+
|
9 |
+
|
10 |
+
try:
|
11 |
+
nlp = spacy.load("en_core_web_sm")
|
12 |
+
except:
|
13 |
+
os.system("python -m spacy download en_core_web_sm")
|
14 |
+
st.experimental_rerun()
|
15 |
+
|
16 |
+
|
17 |
+
demo_option = [
|
18 |
+
{
|
19 |
+
"text": "Planned to go to the Apple Storefront on Tuesday",
|
20 |
+
"spans": [
|
21 |
+
{"start": 0, "end": 7, "label": "Action"},
|
22 |
+
{"start": 21, "end": 37, "label": "Loc"},
|
23 |
+
{"start": 41, "end": 48, "label": "Date"},
|
24 |
+
]
|
25 |
+
}
|
26 |
+
]
|
27 |
+
|
28 |
+
tokenizers = [
|
29 |
+
"bert-base-uncased",
|
30 |
+
"bert-base-cased",
|
31 |
+
"distilbert-base-uncased",
|
32 |
+
"distilbert-base-cased",
|
33 |
+
"roberta-base",
|
34 |
+
]
|
35 |
+
tok = st.selectbox("Pick a tokenizer", tokenizers)
|
36 |
+
spacy_data = st.text_area("Input your NER Span data here")
|
37 |
+
|
38 |
+
if spacy_data or st.button("Or try an example"):
|
39 |
+
run_data = None
|
40 |
+
if spacy_data:
|
41 |
+
try:
|
42 |
+
run_data = json.loads(spacy_data)
|
43 |
+
except JSONDecodeError as e:
|
44 |
+
st.warning(f"Invalid JSON data, try again\n{str(e)}")
|
45 |
+
else:
|
46 |
+
run_data = demo_option
|
47 |
+
if run_data:
|
48 |
+
st.write("Spacy input data:")
|
49 |
+
st.json(run_data)
|
50 |
+
hf_data = spacy_to_hf(run_data, tok)
|
51 |
+
df = Dataset.from_dict(hf_data).to_pandas()
|
52 |
+
st.write("Output huggingface format:")
|
53 |
+
st.dataframe(df)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
spacy-to-hf
|
3 |
+
datasets
|