<jupyter_start><jupyter_text>Chapter 1. Introduction<jupyter_code># %load /Users/hotbaby/github/firstcell.py
import warnings
warnings.filterwarnings('ignore')

import os
import sys
import json
import copy
import tqdm
import math
import time
import heapq
import datetime
import itertools
import functools
import collections
import multiprocessing

import sklearn
import scipy as sp
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import StratifiedKFold, KFold, train_test_split

import lightgbm as lgb
import xgboost as xgb
import catboost as cbt

pd.set_option('display.max_columns', None)

%matplotlib inline<jupyter_output><empty_output><jupyter_text>TF Representation<jupyter_code>from sklearn.feature_extraction.text import CountVectorizer
import seaborn as sns
corpus = [
    'Time flies likes an arrow',
    'Fruit flies like a banana'
]

one_hot_vectorize = CountVectorizer(binary=True)
one_hot = one_hot_vectorize.fit_transform(corpus).toarray()
sns.heatmap(one_hot, annot=True,
           cbar=False, yticklabels=['Sentence 1', 'Sentence 2'])<jupyter_output><empty_output><jupyter_text>**TF-IDF Representaion**<jupyter_code>from sklearn.feature_extraction.text import TfidfVectorizer
import seaborn as sns
tfidf = TfidfVectorizer().fit_transform(corpus).toarray()
sns.heatmap(tfidf, annot=True, cbar=False, yticklabels=['Sentence 1', 'Sentence2'])<jupyter_output><empty_output><jupyter_text>**Creating Tensors**<jupyter_code>def describe(x):
    print('Type: {}'.format(x.type()))
    print('Shape/Size: {}'.format(x.shape))
    print('Values: \n{}'.format(x))
import torch
describe(torch.tensor(range(3)))
describe(torch.randn(2, 3))
describe(torch.ones(3, 4))
x = torch.zeros(2, 3)
describe(x)
x.fill_(5)
describe(x)
import torch
import numpy as np

npy = np.random.rand(2, 3)
describe(torch.from_numpy(npy))<jupyter_output>Type: torch.DoubleTensor
Shape/Size: torch.Size([2, 3])
Values: 
tensor([[0.9098, 0.9817, 0.5670],
        [0.7658, 0.9196, 0.7984]], dtype=torch.float64)<jupyter_text>**Tensor Types and Size**<jupyter_code>x = torch.randn(2, 3)
describe(x)
x = x.long()
describe(x)
x = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.int64)
describe(x)<jupyter_output>Type: torch.LongTensor
Shape/Size: torch.Size([2, 3])
Values: 
tensor([[1, 2, 3],
        [4, 5, 6]])<jupyter_text>**Tensor Operations**<jupyter_code>import torch
x = torch.rand(3, 4)
describe(x)
describe(torch.add(x, x))
describe(x + x)<jupyter_output>Type: torch.FloatTensor
Shape/Size: torch.Size([3, 4])
Values: 
tensor([[1.9952, 0.0169, 0.4567, 0.2211],
        [1.9377, 0.1203, 0.2334, 1.9628],
        [0.8667, 1.0632, 0.8070, 1.6779]])
{'fraction_non_alphanumeric': 0.14200521803950802, 'fraction_numerical': 0.048825941110696984, 'mean_word_length': 6.138297872340425, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '411585', 'license': 'MIT', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1034, 'n_words': 219, 'path': 'NLP-with-PyTorch/Chapter 1. Introduction.ipynb', 'repo_name': 'hotbaby/mmn', 'size': '2683'}