readme
Browse files
README.md
CHANGED
|
@@ -1 +1,120 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Entity Sentiment Classification
|
| 2 |
+
|
| 3 |
+
Classify sentiment (positive, neutral, negative) for named entities in news article text using fine-tuned DistilBERT models.
|
| 4 |
+
|
| 5 |
+
Three classification modes:
|
| 6 |
+
- **marker** — entity wrapped in `[E]...[/E]` special tokens, single-sequence input
|
| 7 |
+
- **qa_m** — question-answering multi-class: "What do you think of the sentiment of {entity}?"
|
| 8 |
+
- **qa_b** — question-answering binary: three hypotheses per entity, argmax of P(yes)
|
| 9 |
+
|
| 10 |
+
Plus a **fastText** baseline using marker-mode text.
|
| 11 |
+
|
| 12 |
+
**Report:** [report.pdf](report.pdf).
|
| 13 |
+
|
| 14 |
+
**Live demo:** https://huggingface.co/spaces/lamossta/entity-sentiment-classification
|
| 15 |
+
|
| 16 |
+
**Logs:** https://telemetry.betterstack.com/team/t529434/tail?s=2383648
|
| 17 |
+
|
| 18 |
+
## Setup
|
| 19 |
+
|
| 20 |
+
### 1. Environment Variables
|
| 21 |
+
|
| 22 |
+
Create a `.env` file in the project root:
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
HF_TOKEN=<your huggingface token> (not needed for the inference)
|
| 26 |
+
BETTERSTACK_SOURCE_TOKEN=<your betterstack token>
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
### 2. Run
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
docker compose up
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
This will install dependencies, download models from HuggingFace, and start the backend and frontend. Everything is accessible on port **7860**:
|
| 36 |
+
- Frontend: http://localhost:7860
|
| 37 |
+
- API: http://localhost:7860/api/
|
| 38 |
+
|
| 39 |
+
## API Endpoints
|
| 40 |
+
|
| 41 |
+
| Endpoint | Method | Description |
|
| 42 |
+
|--------------------|---|---|
|
| 43 |
+
| `/predict` | POST | Classify entities using the marker model |
|
| 44 |
+
| `/predict-all-models` | POST | Classify entities using all available models |
|
| 45 |
+
| `/health` | GET | Health check |
|
| 46 |
+
| `/docs` | GET | Interactive Swagger UI API docs |
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Sending Requests
|
| 50 |
+
|
| 51 |
+
### Request Format
|
| 52 |
+
|
| 53 |
+
```json
|
| 54 |
+
[
|
| 55 |
+
{
|
| 56 |
+
"id": 0,
|
| 57 |
+
"text": "Google had solid Q4 2025 earnings but Microsoft's were not great.",
|
| 58 |
+
"entities": [
|
| 59 |
+
{
|
| 60 |
+
"entity_id": 0,
|
| 61 |
+
"entity_text": "Google",
|
| 62 |
+
"entity_type": "company",
|
| 63 |
+
"positions": [
|
| 64 |
+
{"position_text": "Google", "length": 6, "offset": 0}
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"entity_id": 1,
|
| 69 |
+
"entity_text": "Microsoft",
|
| 70 |
+
"entity_type": "company",
|
| 71 |
+
"positions": [
|
| 72 |
+
{"position_text": "Microsoft", "length": 9, "offset": 40}
|
| 73 |
+
]
|
| 74 |
+
}
|
| 75 |
+
]
|
| 76 |
+
}
|
| 77 |
+
]
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Response Format
|
| 81 |
+
|
| 82 |
+
```json
|
| 83 |
+
[
|
| 84 |
+
{
|
| 85 |
+
"id": 0,
|
| 86 |
+
"entities": [
|
| 87 |
+
{"entity_id": 0, "entity_text": "Google", "classification": "positive"},
|
| 88 |
+
{"entity_id": 1, "entity_text": "Microsoft", "classification": "negative"}
|
| 89 |
+
]
|
| 90 |
+
}
|
| 91 |
+
]
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Local
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
curl -X POST http://localhost:7860/api/predict \
|
| 98 |
+
-H "Content-Type: application/json" \
|
| 99 |
+
-d @sample_input.json
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
curl -X POST http://localhost:7860/api/predict-all-models \
|
| 104 |
+
-H "Content-Type: application/json" \
|
| 105 |
+
-d @sample_input.json
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### HuggingFace Spaces
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
curl -X POST https://<your-space>.hf.space/predict \
|
| 112 |
+
-H "Content-Type: application/json" \
|
| 113 |
+
-d @sample_input.json
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
curl -X POST https://<your-space>.hf.space/predict-all-models \
|
| 118 |
+
-H "Content-Type: application/json" \
|
| 119 |
+
-d @sample_input.json
|
| 120 |
+
```
|