The task here is to automatically assign the MedDRA System Organ Class label (i.e. Adverse Event Body System) to the AELLT (lowest level term) using a LLM.
text_df <-# paste(capture.output(print(df_ADAE[,1 ], n = Inf)), # width = Inf, collapse = "\n")paste(capture.output(write.table(df_ADAE[, 1, drop =FALSE] ,row.names =FALSE,sep =",") ),collapse ="\n" )type_named_entity <-type_object(name =type_string("A classified MedDRA symptom in column AEDECOD"),type =type_enum(description ="Classification label",values = vct_SYS ),confidence =type_string("Confidence in classification: high, medium, or low"))type_named_entities <-type_array(type_named_entity)# ------------chat <-chat_mistral(model ="mistral-large-latest",system_prompt ="You are a medical text classifier expert in MedDRA terminology. The user will give you a data.frame, and you will classify the given symptom in the column AELLT into exactly one of the provided categories")df_classified <- chat$chat_structured( text_df ,type = type_named_entities )df_classified
# A tibble: 74 × 3
name type confidence
<chr> <fct> <chr>
1 ABDOMINAL CRAMPS GASTROINTESTINAL DISORDERS high
2 ABDOMINAL DISCOMFORT GASTROINTESTINAL DISORDERS high
3 ABDOMINAL PAIN GASTROINTESTINAL DISORDERS high
4 AGITATION PSYCHIATRIC DISORDERS high
5 ANTEROSEPTAL INFARCTION CARDIAC DISORDERS high
6 ANXIETY PSYCHIATRIC DISORDERS high
7 ANXIETY AGGRAVATED PSYCHIATRIC DISORDERS high
8 ANXIETY ATTACK PSYCHIATRIC DISORDERS high
9 ATRIAL FIBRILLATION CARDIAC DISORDERS high
10 ATRIAL FLUTTER CARDIAC DISORDERS high
# ℹ 64 more rows
Classification Performance for multiclass classification