hemantn commited on
Commit
3d3c39b
Β·
1 Parent(s): 1f86c13

updated with correct adapter use

Browse files
Files changed (1) hide show
  1. README.md +52 -12
README.md CHANGED
@@ -44,18 +44,49 @@ Install the required dependencies:
44
  pip install transformers torch numpy pandas anarci
45
  ```
46
 
47
- ## πŸš€ Loading Models
48
 
 
49
  ```python
 
 
50
  from transformers import AutoModel, AutoTokenizer
51
- from adapter import AbLang2PairedHuggingFaceAdapter
52
 
53
- # AbLang2
54
  model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
55
  tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
 
 
 
 
 
 
 
 
56
  ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
57
  ```
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  **Note**: Models automatically use GPU when available, otherwise fall back to CPU.
60
 
61
  ## βš™οΈ Available Utilities
@@ -70,30 +101,39 @@ ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
70
 
71
  ## πŸ’‘ Examples
72
 
73
- ### πŸ”— AbLang2 (Paired Sequences)
74
  ```python
 
 
75
  from transformers import AutoModel, AutoTokenizer
 
 
 
 
 
 
 
 
 
 
76
  from adapter import AbLang2PairedHuggingFaceAdapter
77
 
78
- # Load model
79
- model = AutoModel.from_pretrained("your-username/ablang2", trust_remote_code=True)
80
- tokenizer = AutoTokenizer.from_pretrained("your-username/ablang2", trust_remote_code=True)
81
  ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
82
 
83
- # Restore masked paired sequences
84
  masked_seqs = [
85
  ['EVQ***SGGEVKKPGASVKVSCRASGYTFRNYGLTWVRQAPGQGLEWMGWISAYNGNTNYAQKFQGRVTLTTDTSTSTAYMELRSLRSDDTAVYFCAR**PGHGAAFMDVWGTGTTVTVSS',
86
  'DIQLTQSPLSLPVTLGQPASISCRSS*SLEASDTNIYLSWFQQRPGQSPRRLIYKI*NRDSGVPDRFSGSGSGTHFTLRISRVEADDVAVYYCMQGTHWPPAFGQGTKVDIK']
87
  ]
88
  restored = ablang(masked_seqs, mode='restore')
 
89
  ```
90
 
91
  ## πŸ“š Detailed Usage
92
 
93
- For comprehensive examples and detailed usage instructions, see:
94
- - [`test_ablang2_HF_implementation.ipynb`](test_ablang2_HF_implementation.ipynb)
95
-
96
- This notebook demonstrates all utilities with real examples, including alignment features and advanced usage patterns.
97
 
98
  ## πŸ“– Citation
99
 
 
44
  pip install transformers torch numpy pandas anarci
45
  ```
46
 
47
+ ## πŸš€ Loading Models from Hugging Face Hub
48
 
49
+ ### Method 1: Load Model and Tokenizer, then Import Adapter
50
  ```python
51
+ import sys
52
+ import os
53
  from transformers import AutoModel, AutoTokenizer
54
+ from transformers.utils import cached_file
55
 
56
+ # Load model and tokenizer from Hugging Face Hub
57
  model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
58
  tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
59
+
60
+ # Find the cached model directory and import adapter
61
+ adapter_path = cached_file("hemantn/ablang2", "adapter.py")
62
+ cached_model_dir = os.path.dirname(adapter_path)
63
+ sys.path.insert(0, cached_model_dir)
64
+
65
+ # Import and create the adapter
66
+ from adapter import AbLang2PairedHuggingFaceAdapter
67
  ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
68
  ```
69
 
70
+ ### Method 2: Using importlib (Alternative)
71
+ ```python
72
+ import importlib.util
73
+ from transformers import AutoModel, AutoTokenizer
74
+ from transformers.utils import cached_file
75
+
76
+ # Load model and tokenizer
77
+ model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
78
+ tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
79
+
80
+ # Load adapter dynamically
81
+ adapter_path = cached_file("hemantn/ablang2", "adapter.py")
82
+ spec = importlib.util.spec_from_file_location("adapter", adapter_path)
83
+ adapter_module = importlib.util.module_from_spec(spec)
84
+ spec.loader.exec_module(adapter_module)
85
+
86
+ # Create the adapter
87
+ ablang = adapter_module.AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
88
+ ```
89
+
90
  **Note**: Models automatically use GPU when available, otherwise fall back to CPU.
91
 
92
  ## βš™οΈ Available Utilities
 
101
 
102
  ## πŸ’‘ Examples
103
 
104
+ ### πŸ”— AbLang2 (Paired Sequences) - Restore Example
105
  ```python
106
+ import sys
107
+ import os
108
  from transformers import AutoModel, AutoTokenizer
109
+ from transformers.utils import cached_file
110
+
111
+ # 1. Load model and tokenizer from Hugging Face Hub
112
+ model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
113
+ tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
114
+
115
+ # 2. Import adapter
116
+ adapter_path = cached_file("hemantn/ablang2", "adapter.py")
117
+ cached_model_dir = os.path.dirname(adapter_path)
118
+ sys.path.insert(0, cached_model_dir)
119
  from adapter import AbLang2PairedHuggingFaceAdapter
120
 
121
+ # 3. Create adapter
 
 
122
  ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
123
 
124
+ # 4. Restore masked sequences
125
  masked_seqs = [
126
  ['EVQ***SGGEVKKPGASVKVSCRASGYTFRNYGLTWVRQAPGQGLEWMGWISAYNGNTNYAQKFQGRVTLTTDTSTSTAYMELRSLRSDDTAVYFCAR**PGHGAAFMDVWGTGTTVTVSS',
127
  'DIQLTQSPLSLPVTLGQPASISCRSS*SLEASDTNIYLSWFQQRPGQSPRRLIYKI*NRDSGVPDRFSGSGSGTHFTLRISRVEADDVAVYYCMQGTHWPPAFGQGTKVDIK']
128
  ]
129
  restored = ablang(masked_seqs, mode='restore')
130
+ print(f"Restored sequences: {restored}")
131
  ```
132
 
133
  ## πŸ“š Detailed Usage
134
 
135
+ For comprehensive examples of all utilities (seqcoding, rescoding, likelihood, probability, pseudo_log_likelihood, confidence, and more), see:
136
+ - **[`test_ablang2_HF_implementation.ipynb`](test_ablang2_HF_implementation.ipynb)** - Complete notebook with all utilities and advanced usage patterns
 
 
137
 
138
  ## πŸ“– Citation
139