Step 1: Install necessary libraries
If you don't have these installed yet, you can uncomment the next two lines to install the libraries.
!pip install transformers
!pip install adapters
Step 2: Import necessary libraries
from transformers import AutoAdapterModel, AutoTokenizer
Step 3: Load a default pre-trained base model
base_model = AutoAdapterModel.from_pretrained("bert-base-uncased")
Step 4: Load a default working adapter (using a common adapter from Hugging Face)
base_model.load_adapter("adapterhub/bert-base-uncased-pf-sst2", set_active=True)
Step 5: Verify that the adapter has been loaded
print("Adapter loaded and set as active:", base_model.active_adapters)
Step 6: Tokenize input text (Example: Ask about aerospace technology)
input_text = "What is the latest in aerospace technology?"
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
inputs = tokenizer(input_text, return_tensors="pt")
Step 7: Run the model with the active adapter
outputs = base_model(**inputs)
Step 8: Print the model's output (this will display the result of the input text)
print("Model output:", outputs)