File size: 1,482 Bytes
fb1ee97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Text classification demo (Hugging Face)

This repo contains a minimal example to fine-tune a Hugging Face model for text classification.

Quick start (PowerShell):

1. Activate your venv:

```powershell

& "C:\Users\Humberto Arias\recipe_bot\venv\Scripts\Activate.ps1"

```

2. Install dependencies:

```powershell

pip install --upgrade pip

pip install transformers datasets accelerate evaluate huggingface-hub

```

3. Smoke test:

```powershell

python text_classification_demo.py --smoke-test

```

4. Prepare `data/train.csv` with `text,label` columns and run training:

```powershell

python text_classification_demo.py --train_file data/train.csv --model_name_or_path bert-base-uncased --output_dir ./outputs

```

Notes:
- This example is intentionally minimal for learning. For larger runs, use `accelerate` and GPU instances.
- To push to the Hub, `huggingface-cli login` then `trainer.push_to_hub()` can be added.

Model on the Hub
-----------------
The demo model was pushed to: https://huggingface.co/x2-world/recipe-bert

Example inference (after pushing to Hub):
```python

from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline



model_id = "x2-world/recipe-bert"

tokenizer = AutoTokenizer.from_pretrained(model_id)

model = AutoModelForSequenceClassification.from_pretrained(model_id)

clf = pipeline('text-classification', model=model, tokenizer=tokenizer)

print(clf('The pizza was great'))

```