<jupyter_start><jupyter_text>Exploring sentence-transformers library The sentence-transformers library can be installed using pip as shown in the following code:<jupyter_code>%%capture
!pip install sentence_transformers==0.4.0<jupyter_output><empty_output><jupyter_text>The researchers of Sentence-BERT have also made their pre-trained Sentence-BERT models available online. All available pre-trained models can be found here (https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/).We can find pre-trained models named bert-base-nli-cls-token, bert-base-nli-mean-token, roberta-base-nli-max-tokens, distilbert-base-nli-mean-tokens, and so on. Let us understand what this means. - bert-base-nli-cls-token is a pre-trained Sentence-BERT model where we have taken a pre-trained BERT-base model and fine-tuned it with the NLI dataset and the model uses [CLS] token as the sentence representation. - bert-base-nli-mean-token is a pre-trained Sentence-BERT model where we have taken a pre-trained BERT-base model and fine-tuned it with the NLI dataset and the model uses mean pooling strategy for computing sentence representation.  - roberta-base-nli-max-tokens is a pre-trained Sentence-BERT model where we have taken a pre-trained RoBERTa-base model and fine-tuned it with the NLI dataset and the model uses max pooling strategy for computing sentence representation. - distilbert-base-nli-mean-token is a pre-trained Sentence-BERT model where we have taken a pre-trained DistilBERT-base model and fine-tuned it with the NLI dataset and the model uses mean pooling strategy for computing sentence representation. Thus, when we say the pre-trained Sentence-BERT model, it basically implies that we have taken a pre-trained BERT model and finetuned it using the Siamese/triplet network architecture. In the upcoming sections, we will learn how to use the pre-trained Sentence-BERT models.   Computing sentence representation using Sentence-BERT Let us see how to compute sentence representation using pre-trained Sentence-BERT. First, let us import the SentenceTransformer module from our sentence_transformers library. Use the following command:<jupyter_code>from sentence_transformers import SentenceTransformer<jupyter_output><empty_output><jupyter_text>Download and load the pre-trained Sentence-BERT:<jupyter_code>model = SentenceTransformer('bert-base-nli-mean-tokens')<jupyter_output><empty_output><jupyter_text>Define the sentence to which we need to compute the sentence representation:<jupyter_code>sentence = 'paris is a beautiful city'<jupyter_output><empty_output><jupyter_text>Compute the sentence representation using our pre-trained Sentence-BERT model with encode function:<jupyter_code>sentence_representation = model.encode(sentence)<jupyter_output><empty_output><jupyter_text>Now, let us check the shape of our representation:<jupyter_code>print(sentence_representation.shape)<jupyter_output>(768,)
{'fraction_non_alphanumeric': 0.06732403944236655, 'fraction_numerical': 0.0027201632097925877, 'mean_word_length': 5.971563981042654, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '99394', 'license': 'MIT', 'n_tokens_mistral': 862, 'n_tokens_neox': 824, 'n_words': 303, 'path': 'Chapter08/.ipynb_checkpoints/8.03. Exploring sentence-transformers library -checkpoint.ipynb', 'repo_name': 'shizukanaskytree/Getting-Started-with-Google-BERT', 'size': '2941'}