Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model = AutoModelForSequenceClassification.from_pretrained("surendrapratap/gemma-2b-classifier-gguf")
6tokenizer = AutoTokenizer.from_pretrained("surendrapratap/gemma-2b-classifier-gguf")
7
8# Classify text
9text = "Your text here"
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
11
12with torch.no_grad():
13 outputs = model(**inputs)
14 logits = outputs.logits
15 predicted_class_id = logits.argmax().item()
16 probabilities = torch.softmax(logits, dim=-1)
17 confidence = probabilities[0][predicted_class_id].item()
18
19print(f"Predicted class: {predicted_class_id}")
20print(f"Confidence: {confidence:.4f}")1# Clone llama.cpp
2git clone https://github.com/ggerganov/llama.cpp.git
3cd llama.cpp
4
5# Build llama.cpp
6make
7
8# Convert to GGUF
9python convert_hf_to_gguf.py /path/to/this/model --outdir ./
10
11# Quantize (optional)
12./llama-quantize model.gguf model-q4_0.gguf q4_01import mediapipe as mp
2from mediapipe.tasks.python import genai
3
4# Load with MediaPipe LLM (after GGUF conversion)
5llm = genai.LlmInference.create_from_options(
6 genai.LlmInferenceOptions(model_path="model.gguf")
7)
8
9# Generate response
10response = llm.generate_response("Your text here")
11print(response.generated_text)model.safetensors: Model weights in SafeTensors formatconfig.json: Model configurationtokenizer.json: Tokenizer configurationtokenizer.model: SentencePiece tokenizer modellabel_encoder.pkl: Label encoder for class namestraining_metadata.json: Training information1@misc{gemma-2b-classifier-gguf,
2 title={Gemma 2B Text Classifier (GGUF Compatible)},
3 author={Your Name},
4 year={2024},
5 publisher={Hugging Face},
6 url={https://huggingface.co/surendrapratap/gemma-2b-classifier-gguf}
7}