Instructions to use MayZhou/e5-small-lora-ai-generated-detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MayZhou/e5-small-lora-ai-generated-detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("MayZhou/e5-small-lora-ai-generated-detector") model = AutoModelForSequenceClassification.from_pretrained("MayZhou/e5-small-lora-ai-generated-detector", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Download handler.py from MayZhou/e5-small-lora-ai-generated-detector: direct link, hf CLI and curl.
- Browser
- Download file 809 Bytes
-
https://huggingface.co/MayZhou/e5-small-lora-ai-generated-detector/resolve/main/handler.py
- Command line
-
hf download hf://MayZhou/e5-small-lora-ai-generated-detector/handler.py
-
curl -L -o handler.py https://huggingface.co/MayZhou/e5-small-lora-ai-generated-detector/resolve/main/handler.py
809 Bytes
| import torch | |
| import transformers | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| tokenizer = AutoTokenizer.from_pretrained(path) | |
| model = AutoModelForSequenceClassification.from_pretrained(path) | |
| model.eval() | |
| self.pipeline = transformers.pipeline( | |
| "text-classification", model=model, tokenizer=tokenizer | |
| ) | |
| def __call__(self, data): | |
| inputs = data.pop("inputs", data) | |
| result = self.pipeline(inputs, truncation=True, padding=False, max_length=512) | |
| for item in result: | |
| if item['label'] == 'LABEL_0': | |
| item['label'] = 'human-written' | |
| else: | |
| item['label'] = 'AI-generated' | |
| return result |