Deep Learning pour le texte avec PyTorch
Shubham Jain
Instructor
"- Attribuer des étiquettes au texte
{{6}}"
"- Organise et structure les données non structurées
Applications :
Types : binaire, multi-classes, multi-étiquettes {{6}}"
"- Tri en deux catégories
"
{{2}}"
"
{{2}}"
"- Classement dans plusieurs catégories
"- Chaque texte peut se voir attribuer plusieurs étiquettes
"
{{3}}"
"- Les techniques d'encodage précédentes constituent une bonne première étape
- Souvent, on crée trop de caractéristiques et on ne peut pas identifier les mots similaires
"- Exemple :
"- torch.nn.Embedding :
out
Embedding for 'the': tensor([-0.4689, 0.3164, -0.2971, -0.1291, 0.4064])
Embedding for 'cat': tensor([-0.0978, -0.4764, 0.0476, 0.1044, -0.3976])
Embedding for 'sat': tensor([ 0.2731, 0.4431, 0.1275, 0.1434, -0.4721]){{4}}"
"`py
import torch
from torch import nn
----CODE_GLUE---- ```py words = [\"The\", \"cat\", \"sat\", \"on\", \"the\", \"mat\"] word_to_idx = {word: i for i, word in enumerate(words)}inputs = torch.LongTensor([word_to_idx[w] for w in words])embedding = nn.Embedding(num_embeddings=len(words), embedding_dim=10)output = embedding(inputs)print(output)
out
tensor([[ 1.0624, 0.6792, 0.0459, ... -1.0828, -0.4475, 0.4868],
...
[1.5766, 0.0106, 0.1161, ...,, -0.0859, 1.3160, 1.3621]){{6}}"
"`python
def preprocess_sentences(text):
...
----CODE_GLUE----
```python
# Word to index mapping
----CODE_GLUE----
`python
class TextDataset(Dataset):
def init(self, encoded_sentences):
self.data = encoded_sentences
def __len__(self):
return len(self.data)
def __getitem__(self, index):
return self.data[index]
`"
"`python
def text_processing_pipeline(text):
tokens = preprocess_sentences(text)
dataset = TextDataset(tokens)
dataloader = DataLoader(dataset, batch_size=2,
shuffle=True)
return dataloader, vectorizer
----CODE_GLUE----
```python
text = \"Votre texte d'exemple ici.\"
dataloader, vectorizer = text_processing_pipeline(text)
----CODE_GLUE----
`python
embedding = nn.Embedding(num_embeddings=10,
embedding_dim=50)
for batch in dataloader:
output = embedding(batch)
print(output)
`{{1}}"
Deep Learning pour le texte avec PyTorch