prasannabadiger7 commited on
Commit
92fbfb2
Β·
verified Β·
1 Parent(s): 65ad9bb

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +88 -3
  2. app.py +40 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,3 +1,88 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # 🧠 Named Entity Recognition (NER) with BERT
3
+
4
+ This is a web-based Named Entity Recognition (NER) tool powered by a fine-tuned BERT model, built using PyTorch, Hugging Face Transformers, and Streamlit.
5
+
6
+ ## πŸš€ Demo
7
+
8
+ Try the live app (if deployed):
9
+ πŸ‘‰ [Your Streamlit Cloud or Hugging Face Space link]
10
+
11
+ ---
12
+
13
+ ## πŸ“Œ Features
14
+
15
+ - πŸ”Ž Extracts and highlights entities in raw text (PER, LOC, ORG, etc.)
16
+ - πŸ’¬ Clean and interactive Streamlit UI
17
+ - 🧠 Fine-tuned on the CoNLL-2003 dataset
18
+ - ☁️ Deployable via Streamlit Cloud or Hugging Face Spaces
19
+
20
+ ---
21
+
22
+ ## πŸ–₯️ Run Locally
23
+
24
+ 1. Clone this repo:
25
+ ```bash
26
+ git clone https://github.com/prasanna-badiger-7/ner-bert-app.git
27
+ cd ner-bert-app
28
+ ```
29
+
30
+ 2. Install requirements:
31
+ ```bash
32
+ pip install -r requirements.txt
33
+ ```
34
+
35
+ 3. Run the app:
36
+ ```bash
37
+ streamlit run app.py
38
+ ```
39
+
40
+ ---
41
+
42
+ ## πŸ“ Project Structure
43
+
44
+ ```
45
+ ner-bert-app/
46
+ β”‚
47
+ β”œβ”€β”€ app.py # Streamlit frontend
48
+ β”œβ”€β”€ ner_model/ # Saved model & tokenizer
49
+ β”œβ”€β”€ requirements.txt # Dependencies
50
+ └── README.md
51
+ ```
52
+
53
+ ---
54
+
55
+ ## 🧠 Model
56
+
57
+ Fine-tuned `bert-base-cased` on the CoNLL-2003 dataset using Hugging Face Transformers and Datasets.
58
+
59
+ ---
60
+
61
+ ## πŸ“¦ Dependencies
62
+
63
+ - `streamlit`
64
+ - `transformers`
65
+ - `torch`
66
+
67
+ Install all with:
68
+ ```bash
69
+ pip install -r requirements.txt
70
+ ```
71
+
72
+ ---
73
+
74
+ ## πŸ“Έ Example
75
+
76
+ ![Demo Screenshot](demo.png)
77
+
78
+ ---
79
+
80
+ ## πŸ§‘β€πŸ’» Author
81
+
82
+ Made with ❀️ by [Prasanna](https://github.com/your-username)
83
+
84
+ ---
85
+
86
+ ## πŸ“œ License
87
+
88
+ MIT License
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
2
+ import torch
3
+ import streamlit as st
4
+
5
+ model = AutoModelForTokenClassification.from_pretrained('./ner_model')
6
+ tokenizer = AutoTokenizer.from_pretrained('./ner_model')
7
+ label_list = model.config.id2label
8
+
9
+
10
+ def predict_entities(text):
11
+ tokens = tokenizer(text, return_tensors='pt', truncation=True, is_split_into_words=False)
12
+ with torch.no_grad():
13
+ outputs = model(**tokens)
14
+
15
+ predictions = torch.argmax(outputs.logits, dim=2)
16
+ tokens = tokens['input_ids'][0]
17
+ prediction_ids = predictions[0]
18
+
19
+ result = []
20
+ for token_id, pred_id in zip(tokens, prediction_ids):
21
+ token = tokenizer.decode([token_id])
22
+ label = label_list[pred_id.item()]
23
+ if token not in ['[CLS]', '[SEP]', '[PAD]']:
24
+ result.append((token, label))
25
+ return result
26
+
27
+ st.set_page_config(page_title="NER App", layout="wide")
28
+
29
+ st.title("🧠 Named Entity Recognition (NER) with BERT")
30
+ text_input = st.text_area("Enter text to analyze:")
31
+
32
+ if st.button("Analyze"):
33
+ if text_input:
34
+ results = predict_entities(text_input)
35
+ st.markdown("### πŸ” Extracted Entities:")
36
+ for word, label in results:
37
+ if label != "O":
38
+ st.markdown(f"**{word}** β†’ `{label}`")
39
+ else:
40
+ st.warning("Please enter some text.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers
3
+ streamlit