This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from transformers.models.roberta.modeling_roberta import RobertaPreTrainedModel, RobertaConfig | |
| def distill_roberta( | |
| teacher_model : RobertaPreTrainedModel, | |
| ) -> RobertaPreTrainedModel: | |
| """ | |
| Distilates a RoBERTa (teacher_model) like would DistilBERT for a BERT model. | |
| The student model has the same configuration, except for the number of hidden layers, which is // by 2. | |
| The student layers are initilized by copying one out of two layers of the teacher, starting with layer 0. | |
| The head of the teacher is also copied. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any | |
| from transformers import AutoModelForMaskedLM | |
| roberta = AutoModelForMaskedLM.from_pretrained("roberta-large") | |
| def visualize_children( | |
| object : Any, | |
| level : int = 0, | |
| ) -> None: | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from transformers import AutoModelForMaskedLM | |
| roberta = AutoModelForMaskedLM.from_pretrained("roberta-large") | |
| print(roberta) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| def average_word_count(list_of_texts): | |
| """ | |
| Returns the average word count of a list of texts. | |
| """ | |
| total_count = 0 | |
| for text in list_of_texts: | |
| text = text.replace("'", ' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This snippet requires you to install Hugging Face's datasets module | |
| from datasets import load_dataset | |
| import pandas as pd | |
| Dataframe = pd.DataFrame({}) | |
| questions = load_dataset('squad')['train']['question'][:3000] | |
| Dataframe = Dataframe.append(pd.DataFrame({'Text' : questions, 'Source' : 'squad'})) | |
| questions = load_dataset('hotpot_qa', 'distractor')['train']['question'][:3000] |
NewerOlder