<jupyter_start><jupyter_text>**INITIALIZATION:**- I use these three lines of code on top of my each notebooks because it will help to prevent any problems while reloading the same project. And the third line of code helps to make visualization within the notebook.<jupyter_code>#@ INITIALIZATION: 
%reload_ext autoreload
%autoreload 2
%matplotlib inline<jupyter_output><empty_output><jupyter_text>**LIBRARIES AND DEPENDENCIES:**- I have downloaded all the libraries and dependencies required for the project in one particular cell.<jupyter_code>#@ INSTALLING DEPENDENCIES: UNCOMMENT BELOW: 
# !pip install transformers[sentencepiece]
#@ DOWNLOADING LIBRARIES AND DEPENDENCIES:
import torch
import transformers
from transformers import pipeline
from transformers import AutoTokenizer
from transformers import AutoModel
from transformers import AutoModelForSequenceClassification<jupyter_output><empty_output><jupyter_text>**SENTIMENT ANALYSIS:**<jupyter_code>#@ IMPLEMENTATION OF SENTIMENT ANALYSIS PIPELINE:
classifier = pipeline("sentiment-analysis")                                 # Initializing Classifier Object. 
classifier("I've started the HuggingFace course which fascinates me.")      # Inspecting Sentiment.<jupyter_output>No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english)<jupyter_text>**PREPROCESSING WITH TOKENIZER:**- The **tokenizer** will be responsible for:     - Splitting the input into words, subwords, or symbols like puncutation that are also called tokens.     - Mapping each token to an integer.     - Adding additional inputs that may be useful to the model.<jupyter_code>#@ INITIALIZATION OF AUTOTOKENIZER: 
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"                  # Initialization. 
tokenizer = AutoTokenizer.from_pretrained(checkpoint)                           # Initializing Tokenizer. 
#@ CONVERTING INTO TENSORS:
raw_inputs = ["I've started the HuggingFace course which fascinates me.",
              "I will no longer read it's documentation.",
              "I think the course is awesome!"]                                 # Initializing Input Text. 
inputs = tokenizer(raw_inputs, padding=True, truncation=True,                   # Converting into Equal Size. 
                   return_tensors="pt")                                         # Getting PyTorch Tensors. 
print(inputs)                                                                   # Inspecting Tensors with Attention Mask.<jupyter_output>{'input_ids': tensor([[  101,  1045,  1005,  2310,  2318,  1996, 17662, 12172,  2607,  2029,
          6904, 11020, 28184,  2033,  1012,   102],
        [  101,  1045,  2097,  2053,  2936,  3191,  2009,  1005,  1055, 12653,
          1012,   102,     0,     0,     0,     0],
        [  101,  1045,  2228,  1996,  2607,  2003, 12476,   999,   102,     0,
             0,     0,     0,     0,     0,     0]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]])}<jupyter_text>**GOING THROUGH MODEL:**- The vector output by the Transformer module is usually large. It generally has 3 dimensions:    - **Batch size:** The number of sequences processed at a time.     - **Sequence length:** The length of the numerical representation of the sequence.     - **Hidden size:** The vector dimension of each model input.<jupyter_code>#@ INITIALIZATION OF TRANSFORMER MODEL:
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"                  # Initialization. 
model = AutoModel.from_pretrained(checkpoint)                                   # Initializing Model. 
#@ INSPECTING VECTOR DIMENSIONS:
output = model(**inputs)                                                        # Initializing Output. 
print(output.last_hidden_state.shape)                                           # Inspecting Shape. 
#@ INITIALIZATION OF SEQUENCE CLASSIFICATION TRANSFORMER MODEL:
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"                  # Initialization. 
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)          # Initializing Model.
output = model(**inputs)                                                        # Initializing Output. 
print(output.logits.shape)                                                      # Inspecting Shape.<jupyter_output>torch.Size([3, 2])<jupyter_text>**POSTPROCESSING THE OUTPUT:**<jupyter_code>#@ INSPECTING THE OUTPUT:
print(output.logits)
#@ CONVERTING LOGITS INTO PROBABILITIES:
predictions = torch.nn.functional.softmax(output.logits, dim=-1)                # Applying Softmax Function. 
print(predictions)                                                              # Inspecting Prediction Probabilities. 
#@ INSPECTING MODEL ATTRIBUTE:
model.config.id2label<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09260747288067497, 'fraction_numerical': 0.043591803937324224, 'mean_word_length': 2.592352092352092, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '388481', 'license': 'MIT', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1452, 'n_words': 430, 'path': '02. Pipeline Function/PipelineFunction.ipynb', 'repo_name': 'ThinamXx/HuggingFace', 'size': '4978'}