from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
# 모델과 토크나이저 로드
model_name = "emilyalsentzer/Bio_ClinicalBERT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2) # num_labels은 분류할 라벨의 수
# 분류 파이프라인 설정
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer, top_k=None)
# 예제 텍스트
texts = ["The patient shows symptoms of severe acute respiratory syndrome.",
"The treatment was effective and the patient recovered quickly."]
# 분류 수행
results = classifier(texts)
# 결과 출력
for text, result in zip(texts, results):
print(f"Text: {text}")
for label in result:
print(f" {label['label']}: {label['score']:.4f}")