Text Generation
Transformers
Burmese
English
myanmar
burmese
llm
chat
instruction-following
conversational
autoregressive
Instructions to use amkyawdev/myanmar-ghost with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use amkyawdev/myanmar-ghost with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="amkyawdev/myanmar-ghost") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("amkyawdev/myanmar-ghost", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use amkyawdev/myanmar-ghost with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "amkyawdev/myanmar-ghost" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amkyawdev/myanmar-ghost", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/amkyawdev/myanmar-ghost
- SGLang
How to use amkyawdev/myanmar-ghost with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "amkyawdev/myanmar-ghost" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amkyawdev/myanmar-ghost", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "amkyawdev/myanmar-ghost" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amkyawdev/myanmar-ghost", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use amkyawdev/myanmar-ghost with Docker Model Runner:
docker model run hf.co/amkyawdev/myanmar-ghost
File size: 8,122 Bytes
cfb5e7f | 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | """Evaluation script for Myanmar Ghost sentiment model."""
import argparse
import json
import logging
import sys
from pathlib import Path
from typing import Any, Dict
import numpy as np
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, Dataset
from tqdm import tqdm
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from src.utils.logger import setup_logger
from src.utils.metrics import compute_metrics, compute_confusion_matrix
logger = setup_logger("evaluate", log_dir="outputs/logs")
class SentimentDataset(Dataset):
"""Dataset for sentiment classification."""
def __init__(
self,
data,
tokenizer,
max_length: int = 512,
label_mapping: dict = None,
):
self.data = data
self.tokenizer = tokenizer
self.max_length = max_length
self.label_mapping = label_mapping or {
"negative": 0, "neutral": 1, "positive": 2, "sarcastic": 3
}
def __len__(self) -> int:
return len(self.data)
def __getitem__(self, idx: int):
item = self.data[idx]
encoding = self.tokenizer(
item["text"],
truncation=True,
max_length=self.max_length,
padding="max_length",
return_tensors="pt",
)
label = self.label_mapping.get(item.get("label", "neutral"), 1)
return (
encoding["input_ids"].squeeze(0),
encoding["attention_mask"].squeeze(0),
torch.tensor(label, dtype=torch.long),
item.get("text", ""),
)
def load_data(data_path: str):
"""Load evaluation data."""
if data_path.endswith(".jsonl"):
data = []
with open(data_path, "r", encoding="utf-8") as f:
for line in f:
if line.strip():
data.append(json.loads(line))
elif data_path.endswith(".json"):
with open(data_path, "r", encoding="utf-8") as f:
data = json.load(f)
else:
raise ValueError(f"Unsupported format: {data_path}")
return data
def evaluate(
model: nn.Module,
dataloader: DataLoader,
device: torch.device,
class_names: list = None,
) -> Dict[str, Any]:
"""Evaluate the model."""
if class_names is None:
class_names = ["negative", "neutral", "positive", "sarcastic"]
model.eval()
all_predictions = []
all_labels = []
all_texts = []
all_probabilities = []
with torch.no_grad():
for input_ids, attention_mask, labels, texts in tqdm(dataloader, desc="Evaluating"):
input_ids = input_ids.to(device)
attention_mask = attention_mask.to(device)
outputs = model(input_ids, attention_mask)
probs = torch.softmax(outputs, dim=-1)
predictions = outputs.argmax(dim=-1).cpu().tolist()
all_predictions.extend(predictions)
all_labels.extend(labels.tolist())
all_texts.extend(texts)
all_probabilities.extend(probs.cpu().numpy().tolist())
# Compute metrics
metrics = compute_metrics(all_predictions, all_labels, class_names)
# Confusion matrix
cm = compute_confusion_matrix(all_predictions, all_labels)
# Per-sample results
results = []
for i, (text, label, pred, probs) in enumerate(zip(
all_texts, all_labels, all_predictions, all_probabilities
)):
results.append({
"text": text,
"true_label": class_names[label],
"predicted_label": class_names[pred],
"correct": label == pred,
"probabilities": {
class_names[j]: probs[j] for j in range(len(class_names))
},
})
return {
"metrics": metrics,
"confusion_matrix": cm.tolist(),
"class_names": class_names,
"results": results,
}
def save_results(results: Dict, output_path: str) -> None:
"""Save evaluation results to file."""
output_dir = Path(output_path).parent
output_dir.mkdir(parents=True, exist_ok=True)
# Save full results
with open(output_path, "w", encoding="utf-8") as f:
json.dump(results, f, indent=2, ensure_ascii=False)
# Save summary
summary_path = output_dir / "evaluation_summary.txt"
with open(summary_path, "w", encoding="utf-8") as f:
f.write("=" * 60 + "\n")
f.write("EVALUATION SUMMARY\n")
f.write("=" * 60 + "\n\n")
metrics = results["metrics"]
f.write(f"Accuracy: {metrics['accuracy']:.4f}\n")
f.write(f"F1 (weighted): {metrics['f1_weighted']:.4f}\n")
f.write(f"F1 (macro): {metrics['f1_macro']:.4f}\n")
f.write(f"Precision: {metrics['precision_weighted']:.4f}\n")
f.write(f"Recall: {metrics['recall_weighted']:.4f}\n\n")
f.write("Per-class F1:\n")
for name in results["class_names"]:
f1_key = f"f1_{name}"
if f1_key in metrics:
f.write(f" {name}: {metrics[f1_key]:.4f}\n")
f.write(f"\nConfusion Matrix:\n")
f.write(str(np.array(results["confusion_matrix"])) + "\n")
logger.info(f"Results saved to {output_path}")
logger.info(f"Summary saved to {summary_path}")
def main(args):
"""Main evaluation function."""
logger.info("Starting evaluation...")
logger.info(f"Arguments: {vars(args)}")
device = torch.device("cuda" if torch.cuda.is_available() and not args.cpu else "cpu")
logger.info(f"Using device: {device}")
# Load tokenizer
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(args.model_name)
# Load data
logger.info(f"Loading data from {args.data_path}")
data = load_data(args.data_path)
logger.info(f"Total samples: {len(data)}")
# Create dataset and dataloader
dataset = SentimentDataset(data, tokenizer, args.max_length)
dataloader = DataLoader(
dataset,
batch_size=args.batch_size,
shuffle=False,
num_workers=2,
)
# Load model
logger.info(f"Loading model from {args.model_path}")
from src.models.transformer_model import TransformerSentimentModel
model = TransformerSentimentModel(
model_name=args.model_name,
num_labels=4,
)
checkpoint = torch.load(args.model_path, map_location=device)
if "model_state_dict" in checkpoint:
model.load_state_dict(checkpoint["model_state_dict"])
else:
model.load_state_dict(checkpoint)
model.to(device)
# Evaluate
results = evaluate(model, dataloader, device)
# Print summary
logger.info("\n" + "=" * 60)
logger.info("EVALUATION RESULTS")
logger.info("=" * 60)
logger.info(f"Accuracy: {results['metrics']['accuracy']:.4f}")
logger.info(f"F1 (weighted): {results['metrics']['f1_weighted']:.4f}")
logger.info(f"Precision: {results['metrics']['precision_weighted']:.4f}")
logger.info(f"Recall: {results['metrics']['recall_weighted']:.4f}")
# Save results
output_path = args.output_path or "outputs/results/evaluation_results.json"
save_results(results, output_path)
return results["metrics"]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Evaluate Myanmar Ghost model")
parser.add_argument("--data_path", type=str, required=True, help="Test data file")
parser.add_argument("--model_path", type=str, required=True, help="Model checkpoint")
parser.add_argument("--model_name", type=str, default="bert-base-multilingual-cased")
parser.add_argument("--output_path", type=str, default=None, help="Output path")
parser.add_argument("--batch_size", type=int, default=32)
parser.add_argument("--max_length", type=int, default=512)
parser.add_argument("--cpu", action="store_true", help="Use CPU only")
args = parser.parse_args()
main(args)
|