Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
3model_name = 'philomath-1209/programming-language-identification'
4loaded_tokenizer = AutoTokenizer.from_pretrained(model_name)
5loaded_model = AutoModelForSequenceClassification.from_pretrained(model_name)
6
7
8device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9text = """
10PROGRAM Triangle
11 IMPLICIT NONE
12 REAL :: a, b, c, Area
13 PRINT *, 'Welcome, please enter the&
14 &lengths of the 3 sides.'
15 READ *, a, b, c
16 PRINT *, 'Triangle''s area: ', Area(a,b,c)
17 END PROGRAM Triangle
18 FUNCTION Area(x,y,z)
19 IMPLICIT NONE
20 REAL :: Area ! function type
21 REAL, INTENT( IN ) :: x, y, z
22 REAL :: theta, height
23 theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))
24 height = x*SIN(theta); Area = 0.5*y*height
25 END FUNCTION Area
26
27"""
28inputs = loaded_tokenizer(text, return_tensors="pt",truncation=True)
29with torch.no_grad():
30 logits = loaded_model(**inputs).logits
31predicted_class_id = logits.argmax().item()
32loaded_model.config.id2label[predicted_class_id]pip install transformers optimum[onnxruntime] optimum1model_path = "philomath-1209/programming-language-identification"
2import torch
3from transformers import pipeline, AutoTokenizer
4from optimum.onnxruntime import ORTModelForSequenceClassification
5
6tokenizer = AutoTokenizer.from_pretrained(model_path, subfolder="onnx")
7model = ORTModelForSequenceClassification.from_pretrained(model_path, export=False, subfolder="onnx")
8
9text = """
10 PROGRAM Triangle
11 IMPLICIT NONE
12 REAL :: a, b, c, Area
13 PRINT *, 'Welcome, please enter the&
14 &lengths of the 3 sides.'
15 READ *, a, b, c
16 PRINT *, 'Triangle''s area: ', Area(a,b,c)
17 END PROGRAM Triangle
18 FUNCTION Area(x,y,z)
19 IMPLICIT NONE
20 REAL :: Area ! function type
21 REAL, INTENT( IN ) :: x, y, z
22 REAL :: theta, height
23 theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))
24 height = x*SIN(theta); Area = 0.5*y*height
25 END FUNCTION Area
26
27"""
28inputs = tokenizer(text, return_tensors="pt",truncation=True)
29with torch.no_grad():
30 logits = model(**inputs).logits
31predicted_class_id = logits.argmax().item()
32model.config.id2label[predicted_class_id]
33