Tips¶
There are multiple ways to convert a Tensor to a numpy array in PyTorch.
First,
you can call the method Tensor.numpy
.
my_tensor.numpy()
Second,
you can use the function numpy.array
.
import numpy as np
np.array(my_tensor)
It is suggested that you use the function numpy.array
to convert a Tensor to a numpy array.
The reason is that numpy.array
is more generic.
You can also use it to convert other objects (e.g., PIL.Image)
to numpy arrays
while those objects might not have a method named numpy
Tips on the Transformers Python Library for NLP
Tokenization in NLP
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Libraries
SentencePiece
SentencePiece is an unsupervised text tokenizer for Neural Network-based text generation.
Subword Algorithms for NLP
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Classic word representation cannot handle unseen word or rare word well. Character embeddings is one of the solution to overcome out-of-vocabulary (OOV). However, it may be too fine-grained and miss some …
Terminologies and Concepts in NLP
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Word Embedding Character Embedding Subword Embeddling Tokenization
General Language Understanding Evaluation (GLUE)
Natural Language Generation (NLG) Natural Language Generation, as defined by Artificial Intelligence: Natural Language Processing Fundamentals, is the “process …
Difference Between forward and __call__ Methods of a Module in PyTorch
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
- The
Module.__call__
method register all hooks and call the methodModule.forward
. In short, when you train the model you should use the methodforward
, while when you test the …