Spaces:
Runtime error
Runtime error
Update tasks/text.py
Browse files56 unmodified lines575859606162636456 unmodified lines#--------------------------------------------------------------------------------------------# Make random predictions (placeholder for actual model inference)true_labels = test_dataset["label"]predictions = [random.randint(0, 7) for _ in range(len(true_labels))]#--------------------------------------------------------------------------------------------# YOUR MODEL INFERENCE STOPS HERE56 unmodified lines5758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010156 unmodified lines#--------------------------------------------------------------------------------------------# Make random predictions (placeholder for actual model inference)#true_labels = test_dataset["label"]#predictions = [random.randint(0, 7) for _ in range(len(true_labels))]from transformers import DistilBertTokenizerimport numpy as npimport onnxruntime as ort# Load the ONNX model and tokenizerMODEL_PATH = "/Users/hinabandukwala/Documents/frugalai/submission-template/models/distilbert_quantized_dynamic.onnx"tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")ort_session = ort.InferenceSession(MODEL_PATH, providers=["CPUExecutionProvider"])# Preprocess the text datadef preprocess(texts):return tokenizer(texts,padding=True,truncation=True,max_length=365,return_tensors="np")# Run inferencedef predict(texts):inputs = preprocess(texts)ort_inputs = {"input_ids": inputs["input_ids"].astype(np.int64),"attention_mask": inputs["attention_mask"].astype(np.int64)}ort_outputs = ort_session.run(None, ort_inputs)logits = ort_outputs[0]predictions = np.argmax(logits, axis=1)return predictions# Replace the random predictions with actual model predictionstexts = test_dataset["text"]predictions = predict(texts)true_labels = test_dataset["label"]#--------------------------------------------------------------------------------------------# YOUR MODEL INFERENCE STOPS HERE
tasks/text.py+38-1