Spaces:
Sleeping
Sleeping
Jiahuita
commited on
Commit
·
4931f6a
1
Parent(s):
8f3a7a6
updated readme
Browse files- README copy.md +0 -97
- README.md +78 -2
README copy.md
DELETED
|
@@ -1,97 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: News Source Classifier
|
| 3 |
-
emoji: 📰
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: red
|
| 6 |
-
sdk: fastapi
|
| 7 |
-
sdk_version: 0.95.2
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
language: en
|
| 11 |
-
license: mit
|
| 12 |
-
tags:
|
| 13 |
-
- text-classification
|
| 14 |
-
- news-classification
|
| 15 |
-
- LSTM
|
| 16 |
-
- tensorflow
|
| 17 |
-
pipeline_tag: text-classification
|
| 18 |
-
widget:
|
| 19 |
-
- example_title: "Crime News Headline"
|
| 20 |
-
text: "Wife of murdered Minnesota pastor hired 3 men to kill husband after affair: police"
|
| 21 |
-
- example_title: "Science News Headline"
|
| 22 |
-
text: "Scientists discover breakthrough in renewable energy research"
|
| 23 |
-
- example_title: "Political News Headline"
|
| 24 |
-
text: "Presidential candidates face off in heated debate over climate policies"
|
| 25 |
-
model-index:
|
| 26 |
-
- name: News Source Classifier
|
| 27 |
-
results:
|
| 28 |
-
- task:
|
| 29 |
-
type: text-classification
|
| 30 |
-
name: Text Classification
|
| 31 |
-
dataset:
|
| 32 |
-
name: Custom Dataset
|
| 33 |
-
type: Custom
|
| 34 |
-
metrics:
|
| 35 |
-
- name: Accuracy
|
| 36 |
-
type: accuracy
|
| 37 |
-
value: 0.82
|
| 38 |
-
---
|
| 39 |
-
|
| 40 |
-
# News Source Classifier
|
| 41 |
-
|
| 42 |
-
This model classifies news headlines as either Fox News or NBC News using an LSTM neural network.
|
| 43 |
-
|
| 44 |
-
## Model Description
|
| 45 |
-
|
| 46 |
-
- **Model Architecture**: LSTM Neural Network
|
| 47 |
-
- **Input**: News headlines (text)
|
| 48 |
-
- **Output**: Binary classification (Fox News vs NBC)
|
| 49 |
-
- **Training Data**: Large collection of headlines from both news sources
|
| 50 |
-
- **Performance**: Achieves approximately 82% accuracy on the test set
|
| 51 |
-
|
| 52 |
-
## Usage
|
| 53 |
-
|
| 54 |
-
You can use this model directly with a FastAPI endpoint:
|
| 55 |
-
|
| 56 |
-
```python
|
| 57 |
-
import requests
|
| 58 |
-
|
| 59 |
-
response = requests.post(
|
| 60 |
-
"https://huggingface.co/Jiahuita/NewsSourceClassification",
|
| 61 |
-
json={"text": "Your news headline here"}
|
| 62 |
-
)
|
| 63 |
-
print(response.json())
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
Or use it locally:
|
| 67 |
-
|
| 68 |
-
```python
|
| 69 |
-
from transformers import pipeline
|
| 70 |
-
|
| 71 |
-
classifier = pipeline("text-classification", model="Jiahuita/NewsSourceClassification")
|
| 72 |
-
result = classifier("Your news headline here")
|
| 73 |
-
print(result)
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
Example response:
|
| 77 |
-
```json
|
| 78 |
-
{
|
| 79 |
-
"label": "foxnews",
|
| 80 |
-
"score": 0.875
|
| 81 |
-
}
|
| 82 |
-
```
|
| 83 |
-
|
| 84 |
-
## Limitations and Bias
|
| 85 |
-
|
| 86 |
-
This model has been trained on news headlines from specific sources and time periods, which may introduce certain biases. Users should be aware of these limitations when using the model.
|
| 87 |
-
|
| 88 |
-
## Training
|
| 89 |
-
|
| 90 |
-
The model was trained using:
|
| 91 |
-
- TensorFlow 2.13.0
|
| 92 |
-
- LSTM architecture
|
| 93 |
-
- Binary cross-entropy loss
|
| 94 |
-
- Adam optimizer
|
| 95 |
-
|
| 96 |
-
## License
|
| 97 |
-
This project is licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: News Classification
|
| 3 |
+
emoji: 📰
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
+
sdk_version: 0.95.2
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
language: en
|
| 11 |
+
license: mit
|
| 12 |
+
tags:
|
| 13 |
+
- text-classification
|
| 14 |
+
- news-classification
|
| 15 |
+
- LSTM
|
| 16 |
+
- tensorflow
|
| 17 |
+
pipeline_tag: text-classification
|
| 18 |
---
|
| 19 |
|
| 20 |
+
# News Source Classifier
|
| 21 |
+
|
| 22 |
+
This model classifies news headlines as either Fox News or NBC News using a deep learning LSTM (Long Short-Term Memory) neural network architecture.
|
| 23 |
+
|
| 24 |
+
## Model Description
|
| 25 |
+
|
| 26 |
+
### Architecture
|
| 27 |
+
- Input Layer: Embedding layer (vocab_size=74,934, embedding_dim=128)
|
| 28 |
+
- LSTM Layer 1: 128 units with return sequences
|
| 29 |
+
- Dropout Layer 1: For regularization
|
| 30 |
+
- LSTM Layer 2: 64 units
|
| 31 |
+
- Dropout Layer 2: For regularization
|
| 32 |
+
- Output Layer: Dense layer with 2 units (binary classification)
|
| 33 |
+
|
| 34 |
+
### Technical Details
|
| 35 |
+
- Total Parameters: 9,772,676 (37.28 MB)
|
| 36 |
+
- Training Parameters: 9,772,674 (37.28 MB)
|
| 37 |
+
- Input Shape: (41, ) - sequences of length 41
|
| 38 |
+
- Performance: Achieves binary classification of news sources
|
| 39 |
+
|
| 40 |
+
## Usage
|
| 41 |
+
|
| 42 |
+
You can use this model through our REST API:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
import requests
|
| 46 |
+
|
| 47 |
+
def predict_news_source(text):
|
| 48 |
+
response = requests.post(
|
| 49 |
+
"https://jiahuita-news-classification.hf.space/predict",
|
| 50 |
+
json={"text": text},
|
| 51 |
+
headers={"Content-Type": "application/json"}
|
| 52 |
+
)
|
| 53 |
+
return response.json()
|
| 54 |
+
|
| 55 |
+
# Example usage
|
| 56 |
+
headline = "Scientists discover breakthrough in renewable energy research"
|
| 57 |
+
result = predict_news_source(headline)
|
| 58 |
+
print(result)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
Example response:
|
| 62 |
+
```json
|
| 63 |
+
{
|
| 64 |
+
"label": "nbc",
|
| 65 |
+
"score": 0.789
|
| 66 |
+
}
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Limitations and Bias
|
| 70 |
+
|
| 71 |
+
This model has been trained on news headlines from specific sources and time periods, which may introduce certain biases:
|
| 72 |
+
- Training data is limited to two news sources
|
| 73 |
+
- Headlines represent a specific time period
|
| 74 |
+
- Model may be sensitive to writing style rather than just content
|
| 75 |
+
|
| 76 |
+
## Training Details
|
| 77 |
+
|
| 78 |
+
The model was trained using:
|
| 79 |
+
- TensorFlow 2.10.0
|
| 80 |
+
- Binary cross-entropy loss
|
| 81 |
+
- Embedding layer for text representation
|
| 82 |
+
- Dual LSTM layers with dropout for robust feature extraction
|
| 83 |
+
- Dense layer with softmax activation for final classification
|
| 84 |
+
|
| 85 |
+
## License
|
| 86 |
+
This project is licensed under the MIT License.
|