Token Classification
Transformers
Safetensors
English
ai_text_detector
feature-extraction
abacusai
ai-text-detection
ai-generated-text
gemma4
custom_code
Instructions to use abacusai/Smaug-AI-Text-Detector-E4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use abacusai/Smaug-AI-Text-Detector-E4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="abacusai/Smaug-AI-Text-Detector-E4B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("abacusai/Smaug-AI-Text-Detector-E4B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download detect.py from abacusai/Smaug-AI-Text-Detector-E4B: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/abacusai/Smaug-AI-Text-Detector-E4B/resolve/main/detect.py
- Command line
-
hf download hf://abacusai/Smaug-AI-Text-Detector-E4B/detect.py
-
curl -L -o detect.py https://huggingface.co/abacusai/Smaug-AI-Text-Detector-E4B/resolve/main/detect.py
1.36 kB
| """Command line: python detect.py --file essay.txt (or --text "...", or --file texts.jsonl --jsonl with one {"text": ...} per line) | |
| Everything is loaded from this folder: the encoder weights, the two heads, the tokenizer and the scoring constants.""" | |
| import argparse, json, os | |
| import torch | |
| from transformers import AutoModel, AutoTokenizer | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| ap = argparse.ArgumentParser(); ap.add_argument('--text'); ap.add_argument('--file'); ap.add_argument('--jsonl', action='store_true') | |
| ap.add_argument('--model', default=HERE); ap.add_argument('--batch_size', type=int, default=8) | |
| a = ap.parse_args() | |
| tok = AutoTokenizer.from_pretrained(a.model, trust_remote_code=True) | |
| model = AutoModel.from_pretrained(a.model, trust_remote_code=True).to('cuda' if torch.cuda.is_available() else 'cpu').eval() | |
| if a.jsonl: | |
| for line in open(a.file): | |
| r = model.analyze(json.loads(line)['text'], tok, a.batch_size); r.pop('text_scored', None); print(json.dumps(r), flush=True) | |
| else: | |
| r = model.analyze(a.text if a.text is not None else open(a.file).read(), tok, a.batch_size) | |
| print('Verdict:', r.get('verdict'), '| share:', r.get('share'), '| words:', r.get('words')) | |
| for s in r.get('segments', []): | |
| print(f" [{s['label']:>12} {s['confidence']:.2f}] {r['text_scored'][s['start']:s['end']][:100]!r}") | |