Views
No views yet
roberta-baseHUMAN (label 0): Human-written textAI (label 1): AI-generated text["query", "value"] (attention layers)config.json - Model configuration and label mappingsmodel.safetensors - Model weights in SafeTensors formattokenizer.json - Fast tokenizer configurationtokenizer_config.json - Tokenizer configurationvocab.json - Vocabulary mappingsmerges.txt - BPE merge operationsspecial_tokens_map.json - Special token mappingstrainer_root/trainer/task.py script, designed for Google Cloud Vertex AI training jobs.1python task.py \
2 --model-dir gs://your-bucket/model-output \
3 --lora-dir gs://your-bucket/lora-output \
4 --train-data gs://your-bucket/train-data.csv \
5 --valid-data gs://your-bucket/valid-data.jsonl \
6 --train-data-percentage 1.0 \
7 --valid-data-percentage 1.0 \
8 --epochs 3 \
9 --batch-size 8 \
10 --create-mar--model-dir: GCS path for model output--lora-dir: GCS path for LoRA adapter output--train-data: GCS path to CSV training dataset--valid-data: GCS path to JSONL validation dataset--train-data-percentage: Percentage of training data to use (0-1, default: 1.0)--valid-data-percentage: Percentage of validation data to use (0-1, default: 1.0)--epochs: Number of training epochs (default: 3)--batch-size: Training batch size (default: 8)--create-mar: Flag to create TorchServe .mar file for deploymenttext: The input text to classifylabel: The ground truth label (HUMAN or AI){"text": "Sample text content", "label": "HUMAN"}1from transformers import RobertaTokenizerFast, RobertaForSequenceClassification
2
3# Load model and tokenizer
4model = RobertaForSequenceClassification.from_pretrained('./model')
5tokenizer = RobertaTokenizerFast.from_pretrained('./model')
6
7# Classify text
8def classify_text(text):
9 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
10 outputs = model(**inputs)
11 predictions = torch.softmax(outputs.logits, dim=-1)
12 predicted_class = torch.argmax(predictions, dim=-1)
13
14 label_map = {0: "HUMAN", 1: "AI"}
15 return label_map[predicted_class.item()].mar file for TorchServe deployment when the --create-mar flag is used. This creates a production-ready model archive with:roberta_handler.py)1# Start TorchServe with the model
2torchserve --start --model-store /path/to/model-store --models roberta_classifier=roberta_classifier.mar
3
4# Make predictions
5curl -X POST http://localhost:8080/predictions/roberta_classifier \
6 -H "Content-Type: application/json" \
7 -d '{"text": "Your text to classify here"}'AIP_MODEL_DIR, AIP_CHECKPOINT_DIR, AIP_TENSORBOARD_LOG_DIR)transformerstorchdatasetspeftscikit-learnpandasgoogle-cloud-storagetorch-model-archivertorchserveDataCollatorWithPadding for efficient batching[human_score, ai_score]trainer_root/trainer/task.py. For deployment issues, consult the TorchServe or Vertex AI documentation based on your deployment method.