Update classify-dataset.py
Browse files- Update dependencies to avoid wheel installation issues with `sentencepiece`
- Fix GPU device ID error
- classify-dataset.py +4 -3
classify-dataset.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# /// script
|
| 3 |
-
# requires-python = "
|
| 4 |
# dependencies = [
|
|
|
|
| 5 |
# "sieves[engines]>=0.17.4",
|
| 6 |
# "typer>=0.12,<1",
|
| 7 |
# "datasets",
|
|
@@ -402,11 +403,11 @@ def classify(
|
|
| 402 |
|
| 403 |
# Build model.
|
| 404 |
info = HfApi().model_info(model)
|
| 405 |
-
device =
|
| 406 |
zeroshot_tag = "zero-shot-classification"
|
| 407 |
# Explicitly designed for zero-shot classification: build directly as pipeline.
|
| 408 |
if info.pipeline_tag == zeroshot_tag or zeroshot_tag in set(info.tags or []):
|
| 409 |
-
logger.info("Initializing zero-shot
|
| 410 |
model = transformers.pipeline(zeroshot_tag, model=model, device=device)
|
| 411 |
# Otherwise: build Outlines model around it to enforce structured generation.
|
| 412 |
else:
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# /// script
|
| 3 |
+
# requires-python = "==3.12"
|
| 4 |
# dependencies = [
|
| 5 |
+
# "transformers[torch]>=4.35",
|
| 6 |
# "sieves[engines]>=0.17.4",
|
| 7 |
# "typer>=0.12,<1",
|
| 8 |
# "datasets",
|
|
|
|
| 403 |
|
| 404 |
# Build model.
|
| 405 |
info = HfApi().model_info(model)
|
| 406 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
| 407 |
zeroshot_tag = "zero-shot-classification"
|
| 408 |
# Explicitly designed for zero-shot classification: build directly as pipeline.
|
| 409 |
if info.pipeline_tag == zeroshot_tag or zeroshot_tag in set(info.tags or []):
|
| 410 |
+
logger.info("Initializing zero-shot classification pipeline.")
|
| 411 |
model = transformers.pipeline(zeroshot_tag, model=model, device=device)
|
| 412 |
# Otherwise: build Outlines model around it to enforce structured generation.
|
| 413 |
else:
|