MountainUsurper commited on
Commit
d5f216f
·
verified ·
1 Parent(s): 1463dc2

Create config/config.py

Browse files
Files changed (1) hide show
  1. config/config.py +109 -0
config/config.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # config/config.py
2
+ import os
3
+ import torch
4
+
5
+ class EnhancedConfig:
6
+ """Configuration class holding all parameters for the biomedical pipeline."""
7
+
8
+ # SOTA Models (2024-2025)
9
+ CLAIM_MODELS = [
10
+ 'Nithiwat/xlm-roberta-base_claimbuster',
11
+ 'microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext'
12
+ ]
13
+
14
+ # BioLORD-2023 is SOTA for biomedical similarity
15
+ EMBEDDING_MODEL = 'FremyCompany/BioLORD-2023-M'
16
+ EMBEDDING_FALLBACK = 'pritamdeka/S-PubMedBert-MS-MARCO'
17
+
18
+ # NLI Models
19
+ NLI_MODELS = [
20
+ 'gsarti/biobert-nli',
21
+ 'microsoft/deberta-v3-large'
22
+ ]
23
+
24
+ # Cross-encoder for reranking
25
+ CROSS_ENCODER_MODEL = 'cross-encoder/ms-marco-MiniLM-L-12-v2'
26
+
27
+ # Summarization models
28
+ BIOBART_MODEL = 'GanjinZero/biobart-v2-large'
29
+ PEGASUS_MODEL = 'google/pegasus-xsum'
30
+ FACTCC_MODEL = 'tals/albert-xlarge-vitaminc-mnli'
31
+
32
+ # Whisper for audio
33
+ WHISPER_MODEL = 'medium'
34
+
35
+ # Paths - Use environment variables or defaults
36
+ CACHE_DIR = os.getenv('CACHE_DIR', 'enhanced_cache')
37
+ PUBMED_CACHE_DIR = os.getenv('PUBMED_CACHE_DIR', os.path.join(CACHE_DIR, 'pubmed'))
38
+ MODEL_CACHE_DIR = os.getenv('MODEL_CACHE_DIR', os.path.join(CACHE_DIR, 'models'))
39
+
40
+ # Enhanced Parameters
41
+ TOP_K_INITIAL = int(os.getenv('TOP_K_INITIAL', '30'))
42
+ TOP_K_RERANK = int(os.getenv('TOP_K_RERANK', '10'))
43
+ MAX_PUBMED_RESULTS = int(os.getenv('MAX_PUBMED_RESULTS', '50'))
44
+ CLAIM_THRESHOLD = float(os.getenv('CLAIM_THRESHOLD', '0.30'))
45
+ ENSEMBLE_THRESHOLD = float(os.getenv('ENSEMBLE_THRESHOLD', '0.35'))
46
+
47
+ # Confidence thresholds
48
+ HIGH_CONFIDENCE = float(os.getenv('HIGH_CONFIDENCE', '0.60'))
49
+ MEDIUM_CONFIDENCE = float(os.getenv('MEDIUM_CONFIDENCE', '0.35'))
50
+ LOW_CONFIDENCE = float(os.getenv('LOW_CONFIDENCE', '0.20'))
51
+
52
+ # NLI thresholds
53
+ ENTAILMENT_THRESHOLD = float(os.getenv('ENTAILMENT_THRESHOLD', '0.60'))
54
+ CONTRADICTION_THRESHOLD = float(os.getenv('CONTRADICTION_THRESHOLD', '0.60'))
55
+
56
+ # PubMed API - Use environment variables for security
57
+ ENTREZ_EMAIL = os.getenv('EMAIL_ADDRESS', 'your-email@example.com') # Use environment variable
58
+ ENTREZ_API_KEY = os.getenv('PUBMED_API_KEY', '') # Use environment variable
59
+
60
+ # Features - Use environment variables for toggling
61
+ USE_QUERY_EXPANSION = os.getenv('USE_QUERY_EXPANSION', 'True').lower() == 'true'
62
+ USE_RERANKING = os.getenv('USE_RERANKING', 'True').lower() == 'true'
63
+ USE_BM25_HYBRID = os.getenv('USE_BM25_HYBRID', 'True').lower() == 'true'
64
+
65
+ # --- New parameters for robustness ---
66
+ MAX_RETRY_ATTEMPTS = int(os.getenv('MAX_RETRY_ATTEMPTS', '3'))
67
+ CACHE_EXPIRATION_HOURS = int(os.getenv('CACHE_EXPIRATION_HOURS', '24'))
68
+ PUBMED_TIMEOUT_SECONDS = int(os.getenv('PUBMED_TIMEOUT_SECONDS', '30'))
69
+ # Options: 'mock', 'rule-based', 'none'
70
+ FALLBACK_STRATEGY = os.getenv('FALLBACK_STRATEGY', 'mock')
71
+
72
+ # Add a list of additional datasets for training/evaluation
73
+ ADDITIONAL_DATASETS = [
74
+ 'scifact', # Scientific fact checking
75
+ 'fever', # Fact extraction and verification
76
+ 'mednli' # Medical Natural Language Inference
77
+ ]
78
+
79
+ # Add flags for using online/evidence retrieval
80
+ USE_ONLINE_EVIDENCE = os.getenv('USE_ONLINE_EVIDENCE', 'True').lower() == 'true'
81
+ USE_LOCAL_CACHE = os.getenv('USE_LOCAL_CACHE', 'True').lower() == 'true'
82
+
83
+ def __init__(self):
84
+ """Initialize the configuration and determine the device."""
85
+ # Determine the device (GPU if available, otherwise CPU)
86
+ # This is important to set early so other components can use it
87
+ self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
88
+ print(f"Config: Using device: {self.device}")
89
+
90
+ # Ensure cache directories exist
91
+ os.makedirs(self.CACHE_DIR, exist_ok=True)
92
+ os.makedirs(self.PUBMED_CACHE_DIR, exist_ok=True)
93
+ os.makedirs(self.MODEL_CACHE_DIR, exist_ok=True)
94
+ print(f"Config: Cache directories created/verified.")
95
+ print(f"Config: Model cache directory: {self.MODEL_CACHE_DIR}")
96
+ print(f"Config: PubMed cache directory: {self.PUBMED_CACHE_DIR}")
97
+
98
+ def __repr__(self):
99
+ """String representation of the config for debugging."""
100
+ return f"EnhancedConfig(device={self.device}, models={len(self.NLI_MODELS)} NLI models loaded)"
101
+
102
+ # You can add more methods here if needed, for example:
103
+ # def update_from_dict(self, config_dict: dict):
104
+ # """Update config attributes from a dictionary."""
105
+ # for key, value in config_dict.items():
106
+ # if hasattr(self, key):
107
+ # setattr(self, key, value)
108
+ # else:
109
+ # print(f"Warning: Unknown config key '{key}' provided.")