Skip to content
Snippets Groups Projects
Commit eed59417 authored by Ivan Pavlovich's avatar Ivan Pavlovich
Browse files

Added wrapper Ollama to test ollama models

parent d56fd172
Branches
No related tags found
No related merge requests found
No preview for this file type
...@@ -85,7 +85,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store ...@@ -85,7 +85,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store
for part in entrie["MedlineCitation"]["Article"]["Journal"]["Title"]: for part in entrie["MedlineCitation"]["Article"]["Journal"]["Title"]:
if "#text" in part: if "#text" in part:
data["Title"] += part["#text"] data["Title"] += part["#text"]
elif isinstance(entrie["MedlineCitation"]["Article"]["Journal"]["Title"], object): elif not isinstance(entrie["MedlineCitation"]["Article"]["Journal"]["Title"], str):
data["Title"] = entrie["MedlineCitation"]["Article"]["Journal"]["Title"]["#text"] data["Title"] = entrie["MedlineCitation"]["Article"]["Journal"]["Title"]["#text"]
else: else:
data["Title"] = entrie["MedlineCitation"]["Article"]["Journal"]["Title"] data["Title"] = entrie["MedlineCitation"]["Article"]["Journal"]["Title"]
...@@ -95,7 +95,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store ...@@ -95,7 +95,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store
for part in entrie["MedlineCitation"]["Article"]["ArticleTitle"]: for part in entrie["MedlineCitation"]["Article"]["ArticleTitle"]:
if "#text" in part: if "#text" in part:
data["ArticleTitle"] += part["#text"] data["ArticleTitle"] += part["#text"]
elif isinstance(entrie["MedlineCitation"]["Article"]["ArticleTitle"], object): elif not isinstance(entrie["MedlineCitation"]["Article"]["ArticleTitle"], str):
data["ArticleTitle"] = entrie["MedlineCitation"]["Article"]["ArticleTitle"]["#text"] data["ArticleTitle"] = entrie["MedlineCitation"]["Article"]["ArticleTitle"]["#text"]
else: else:
data["ArticleTitle"] = entrie["MedlineCitation"]["Article"]["ArticleTitle"] data["ArticleTitle"] = entrie["MedlineCitation"]["Article"]["ArticleTitle"]
...@@ -106,7 +106,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store ...@@ -106,7 +106,7 @@ def getPubmedData(term, date_min, date_max, nb_items = -1, debug = False, store
for part in entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"]: for part in entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"]:
if "#text" in part: if "#text" in part:
data["Abstract"] += part["#text"] data["Abstract"] += part["#text"]
elif isinstance(entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"], object): elif not isinstance(entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"], str):
data["Abstract"] = entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"]["#text"] data["Abstract"] = entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"]["#text"]
else: else:
data["Abstract"] = entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"] data["Abstract"] = entrie["MedlineCitation"]["Article"]["Abstract"]["AbstractText"]
......
File added
from ollama import chat
from ollama import ChatResponse
import json
NCDS = [
"Non-Communicable Diseases",
"Diabetes",
"Cancer",
"Chronic respiratory disease",
"Cardiovascular diseases",
"Mental Health",
"Diabetes type 1",
"Diabetes type 2"
]
def classify(model, sequence, labels):
prompt = f'I need you to give me the labels that could be given to the text (keep in mind that u can put multiple labels and select only the labels that i give you):\
text: {sequence}\
labels: {labels}\
Give the response in json format "labels": [] with no text at all'
response: ChatResponse = chat(model=model, messages=[
{
'role': 'user',
'content': prompt,
},
])
json_str = response.message.content.strip().lstrip('```json').strip()
if json_str.endswith("```"):
json_str = json_str[0:-3]
responce_json = json.loads(json_str)
print(responce_json)
res = {}
for label in labels:
res[label] = label in responce_json["labels"]
return
text = "Theranostic drugs represent an emerging path to deliver on the promise of precision medicine. However, bottlenecks remain in characterizing theranostic targets, identifying theranostic lead compounds, and tailoring theranostic drugs. To overcome these bottlenecks, we present the Theranostic Genome, the part of the human genome whose expression can be utilized to combine therapeutic and diagnostic applications. Using a deep learning-based hybrid human-AI pipeline that cross-references PubMed, the Gene Expression Omnibus, DisGeNET, The Cancer Genome Atlas and the NIH Molecular Imaging and Contrast Agent Database, we bridge individual genes in human cancers with respective theranostic compounds. Cross-referencing the Theranostic Genome with RNAseq data from over 17'000 human tissues identifies theranostic targets and lead compounds for various human cancers, and allows tailoring targeted theranostics to relevant cancer subpopulations. We expect the Theranostic Genome to facilitate the development of new targeted theranostics to better diagnose, understand, treat, and monitor a variety of human cancers."
classify('llama3.2', text, NCDS)
\ No newline at end of file
...@@ -108,7 +108,7 @@ for disease_label in DISEASES_LABELS: ...@@ -108,7 +108,7 @@ for disease_label in DISEASES_LABELS:
if MODELS[model]["isHuggingFace"]: if MODELS[model]["isHuggingFace"]:
predictions = MODELS[model]["predict"](pipline, title+abstract, DISEASES_LABELS, data["treshold"]) predictions = MODELS[model]["predict"](pipline, title+abstract, DISEASES_LABELS, data["treshold"])
else: else:
predictions = MODELS[model]["predict"](title+abstract, DISEASES_LABELS) predictions = MODELS[model]["predict"](model, title+abstract, DISEASES_LABELS)
end = time.time() end = time.time()
......
...@@ -2,10 +2,16 @@ import sys ...@@ -2,10 +2,16 @@ import sys
import os import os
# Ajouter le répertoire parent au chemin de recherche # Ajouter le répertoire parent au chemin de recherche
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
from models.ZeroShotClassifier.HuggingFace.zero_shot_classification import create_classifier, classify from models.ZeroShotClassifier.HuggingFace.zero_shot_classification import create_classifier, classify
import models.LLM.Ollama as ollama
MODELS = { MODELS = {
'facebook/bart-large-mnli': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier} 'facebook/bart-large-mnli': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier},
'MoritzLaurer/bge-m3-zeroshot-v2.0': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier},
'MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier},
'MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier},
'MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli': {'predict': classify, 'isHuggingFace': True, 'pipline': create_classifier},
'llama3.2': {'predict': ollama.classify, 'isHuggingFace': False, 'pipline': None}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment