diff --git a/models/FineTuning/fine_tuning_wrapper.py b/models/FineTuning/fine_tuning_wrapper.py index e6156d71e4325638f9fa6bb45905d8a71f798d0c..f6afc779fe0509931f482bf0ce6eacc3146c4083 100644 --- a/models/FineTuning/fine_tuning_wrapper.py +++ b/models/FineTuning/fine_tuning_wrapper.py @@ -1,3 +1,13 @@ +# ----------------------------- +# Le script ne fait rien. Il met a disposition deux fonction une qui créer un classifier à +# partir du model fine-tuner (./model). Le deuxième classifie une sequence sur des label en utilisant le classifier +# créer dans la première fonction +# +# Ce script ne prend pas de paramètres. +# +# Auteur : Pavlovich Ivan +# ----------------------------- + from transformers import pipeline import os import sys diff --git a/models/FineTuning/finetunning-multi-label.py b/models/FineTuning/finetunning-multi-label.py index dda2f01d56f13dba538e4d4977d44d5d9d792a79..a397a1cde486773804f967d4a69d741234e8a48f 100644 --- a/models/FineTuning/finetunning-multi-label.py +++ b/models/FineTuning/finetunning-multi-label.py @@ -1,4 +1,12 @@ -# https://medium.com/@lidores98/finetuning-huggingface-facebook-bart-model-2c758472e340 +# ----------------------------- +# Le script affine le modèle BART-Large-MNLI de Facebook AI sur les articles stoquer localement (dataSources/PubMed/save/save_3_years.json) +# +# Ce script ne prend pas de paramètres. +# +# Basée sur : https://medium.com/@lidores98/finetuning-huggingface-facebook-bart-model-2c758472e340 +# +# Auteur : Pavlovich Ivan +# ----------------------------- import pandas as pd import torch @@ -18,7 +26,7 @@ from parsers.jsonParser import parseJsonFile from variables.pubmed import NCDS, NCDS_MESH_TERM DATASET_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../testModel/dataset")) -TMP_DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../dataSources/PubMed/tmp")) +TMP_DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../dataSources/PubMed/save")) SAVE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "./save")) MODEL_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "./model")) LOGS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "./logs")) diff --git a/models/FineTuning/job_launch.sbatch b/models/FineTuning/job_launch.sbatch index 71a6bb93dcaf65e0fb0678f928d5b0d23734f55d..105a8c91870276d43fc237b64ea51df5bd664db9 100644 --- a/models/FineTuning/job_launch.sbatch +++ b/models/FineTuning/job_launch.sbatch @@ -13,4 +13,4 @@ module load CUDA/12.3.0 GCC/12.2.0 Python/3.10.8 Qt5/5.15.7 source ../../.venv/bin/activate -python3 facebook-bart-large-mnli.py \ No newline at end of file +python3 finetunning-multi-label.py \ No newline at end of file diff --git a/models/HuggingFace/zero_shot_classification.py b/models/HuggingFace/zero_shot_classification.py index 0e8533d242ac1dcfbb21f8cc1fce7d30ffebd748..9aebb04a15b9b872f5d1fabd25843db88ec5d0cd 100644 --- a/models/HuggingFace/zero_shot_classification.py +++ b/models/HuggingFace/zero_shot_classification.py @@ -1,35 +1,18 @@ +# ----------------------------- +# Le script ne fait rien. Il met a disposition deux fonction une qui créer une pipline zero-shot classification à +# partir d un model hugging face. Le deuxième classifie une sequence sur des label en utilisant le classifier +# créer dans la première fonction +# +# Ce script ne prend pas de paramètres. +# +# Auteur : Pavlovich Ivan +# ----------------------------- + from transformers import pipeline import torch import time -LABELS = [ - "Diabetes", - "Cancer", - "Chronic respiratory disease", - "Cardiovascular diseases", - "Mental Health", - "Diabetes type 1", - "Diabetes type 2" -] - -# LABELS = [ -# "Neoplasms", -# "Diabetes Mellitus", -# "Male", -# "Blood Cells", -# "Arthritis, Infectious" -# ] - -MODELS = [ - "facebook/bart-large-mnli", # https://huggingface.co/facebook/bart-large-mnli - "MoritzLaurer/bge-m3-zeroshot-v2.0", # https://huggingface.co/MoritzLaurer/bge-m3-zeroshot-v2.0 - "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli", - "MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33", - "MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli", - "microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract" # https://huggingface.co/microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract -] - -def create_classifier(model = MODELS[0]): +def create_classifier(model): print(f" CUDA available: {torch.cuda.is_available()}") print(f"CUDA version: {torch.version.cuda}") print(f"GPUs number: {torch.cuda.device_count()}") diff --git a/models/LLM/Cohere/cohere_wrapper.py b/models/LLM/Cohere/cohere_wrapper.py index 4a3d7de663242ffd1500cbb5b1f1327e17415bdf..e1546cf9b6a7f7600af3d8ad041ca01de7910c5d 100644 --- a/models/LLM/Cohere/cohere_wrapper.py +++ b/models/LLM/Cohere/cohere_wrapper.py @@ -1,3 +1,13 @@ +# ----------------------------- +# Le script ne fait rien. Il met a disposition deux fonction une qui créer un client cohere à +# partir d une clé. Le deuxième classifie une sequence sur des label en utilisant le client +# créer dans la première fonction +# +# Ce script ne prend pas de paramètres. +# +# Auteur : Pavlovich Ivan +# ----------------------------- + import cohere import json import time diff --git a/models/LLM/Gemini/gemini.py b/models/LLM/Gemini/gemini.py index 5bb6fd8d2eed13be796c5661e773b168c1a216ff..7cb8aeb6bb6673dc93699ceff378881f71e9b7ad 100644 --- a/models/LLM/Gemini/gemini.py +++ b/models/LLM/Gemini/gemini.py @@ -1,3 +1,13 @@ +# ----------------------------- +# Le script ne fait rien. Il met a disposition deux fonction une qui créer un chat gemini. +# La deuxième classifie une sequence sur des label en utilisant le chat créer dans la première fonction +# +# Ce script ne prend pas de paramètres. +# +# Auteur : Pavlovich Ivan +# ----------------------------- + + import os import google.generativeai as genai import json diff --git a/models/LLM/Ollama/ollama_wrapper.py b/models/LLM/Ollama/ollama_wrapper.py index c96c276e1fdce1dc2bcc54431a0965b7947073c5..30a6e0c4500ed2fc8bf791ec645d781affdfd068 100644 --- a/models/LLM/Ollama/ollama_wrapper.py +++ b/models/LLM/Ollama/ollama_wrapper.py @@ -1,19 +1,17 @@ +# ----------------------------- +# Le script ne fait rien. Il met a disposition une fonction qui classifie une sequence sur des label en utilisant un model ollama +# +# Ce script ne prend pas de paramètres. +# +# Auteur : Pavlovich Ivan +# ----------------------------- + + from ollama import chat from ollama import ChatResponse import json import time -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 = '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):\n'