Deep Learning para texto con PyTorch
Shubham Jain
Instructor
"- Asignar etiquetas al texto
{{6}}"
"- Organiza y da estructura a datos no estructurados
Aplicaciones:
Tipos: binario, multiclase, multilabel {{6}}"
"- Clasificación en dos categorías
"
{{2}}"
"
{{2}}"
"- Clasificación en múltiples categorías
"- A cada texto se le pueden asignar varias etiquetas
"
{{3}}"
"- Las técnicas de codificación anteriores son un buen primer paso
- A menudo se crean demasiadas características y no se pueden identificar palabras similares
"- Ejemplo:
"- torch.nn.Embedding:
out
Embedding para 'the': tensor([-0.4689, 0.3164, -0.2971, -0.1291, 0.4064])
Embedding para 'cat': tensor([-0.0978, -0.4764, 0.0476, 0.1044, -0.3976])
Embedding para '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 = \"Tu texto de ejemplo aquí.\"
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 para texto con PyTorch