Tuesday, August 9, 2022

[what is] "TypeError: 'NoneType' object is not callable"

 .

The Python "TypeError: 'NoneType' object is not callable" occurs when we try to call a None value as if it were a function. To solve the error, track down where the None value comes from and correct the assignment or remove the parenthesis

.

TypeError: 'NoneType' object is not callable in Python | bobbyhadz

Read More

Monday, August 8, 2022

[what is] Python Assert Statement?

 .

In Python, the assert statement is used to continue the execution if the given condition evaluates to True. If the assert condition evaluates to False, then it raises the AssertionError exception with the specified error message.

.

Example:

x = 10

assert x > 0

print('x is a positive number.')

.

Read More

[how to] solver error: ModuleNotFoundError: No module named 'torch'

 

Error:

ModuleNotFoundError: No module named 'torch'

Solution:

(In Conda) Run installation command via conda terminal:

conda install -c pytorch pytorch

Read More

[how to] solve error: error: subprocess-exited-with-error Building wheel for tokenizers (pyproject.toml) did not run successfully. exit code: 1 [166 lines of output]

 .

Error:

During installation of transformers=3.0.2 i.e. !pip install transformers==3.0.2 the following error were displayed:

  error: subprocess-exited-with-error
  
  Building wheel for tokenizers (pyproject.toml) did not run successfully.
  exit code: 1
  
  [166 lines of output]


Solution:

remove the version number i.e.
!pip install transformers
Read More

[how to] solve error: executing Jupyter command 'lab' [WinError 5] Access is denied



 .

Error:
executing Jupyter command 'lab' [WinError 5] Access is denied

.

Solution:

Run anaconda as Administrator.

.


Read More

[how to] solve error: linker `link.exe` not found | = note: program not found


 

.

Error:

error: linker `link.exe` not found | = note: program not found note: the msvc targets depend on the msvc linker but `link.exe` was not found note: please ensure that VS 2013, VS 2015, VS 2017, VS 2019 or VS 2022 was installed with the Visual C++ option error: could not compile `memchr` due to previous error

.

Solution:

Install Microsoft VCC Build Tool

Microsoft C++ Build Tools - Visual Studio


Tick the option: Desktop Development With C++


Read More

[how to] install RUST via CONDA


 

.

conda install -c conda-forge rust

.

Read More

[how to] solve transformers Install Error: error can‘t find rust compiler

 .

Install transformers after reinstalling the system. If you encounter a bug, record it and check it later.

When reinstalling with pip install transformers command under windows, an error is reported:

error: can't find Rust compiler
      
    If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
      
    To update pip, run:
      
        pip install --upgrade pip
      
    and then retry package installation.
      
    If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
    [end of output]
  
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

According to the error prompt, first run pip install -- upgrade pip is invalid, and then install Rust Compiler according to the error prompt. First go to the official website to download the corresponding installation package, select the 64-bit installation file according to my actual situation, then click the downloaded exe file to install, and select the default configuration during the installation process.

According to the instructions on the official website, all tools of rust are in the  ~/.cargo/bin directory includes commands:  rustccargo and rustup . Therefore, it needs to be configured into the environment variable, but windows will configure it automatically, but the configured environment variable will take effect only after restarting the computer under windows. After restarting, run the installation command again:

pip install transformers

The result is a successful installation.

.

Alternatively, install via conda terminal.

reference:

[Solved] transformers Install Error: error can‘t find rust compiler | ProgrammerAH

Read More

Sunday, August 7, 2022

Colab Word2Vec Using Emoji2Vec dataset

 .

Import the required libraries:

import gensim
from gensim.models import word2vec
from gensim.models import KeyedVectors
from sklearn.metrics.pairwise import cosine_similarity

.

Upload Word2Vec emoji2vec dataset into /content folder:

.

Alternatively, get from Archive.org:

!wget 'https://archive.org/download/word-embeddings/emoji2vec.bin' -P '/content'

.

Load Emoji2Vec model

import gensim.models as gsm
e2v = gensim.models.KeyedVectors.load_word2vec_format('/content/emoji2vec.bin', binary=True)
happy_vector = e2v['😂']    # Produces an embedding vector of length 300
print(happy_vector.shape)

>>>>(300,)

.

Find cosine similarity:

v_king = e2v["🤴"
v_queen = e2v["👸"]
print(v_king.shape)
print(v_queen.shape)
cosine_similarity([v_king],[v_queen])

>>>>(300,)

(300,)

array([[0.48802766]], dtype=float32)

.

Reference:

https://github.com/uclnlp/emoji2vec



Read More

Colab Word2Vec Using Google News dataset

.

Import the required libraries:

import gensim
from gensim.models import word2vec
from gensim.models import KeyedVectors
from sklearn.metrics.pairwise import cosine_similarity

.

Download Word2Vec GoogleNews 300 dataset using Gensim downloader:

import gensim.downloader as api
wv = api.load('word2vec-google-news-300')
vec_king = wv['king']
print(vec_king.shape)

>>>>(300,)

.

Limit the vocabulary size to 50,000 words:

EMBEDDING_FILE = '/root/gensim-data/word2vec-google-news-300/word2vec-google-news-300.gz'
word_vectors = KeyedVectors.load_word2vec_format(EMBEDDING_FILE, binary=True,limit=50000)

.

Find cosine similarity:

v_apple = word_vectors["apple"
v_mango = word_vectors["mango"]
print(v_apple.shape)
print(v_mango.shape)
cosine_similarity([v_mango],[v_apple])

>>>>(300,)

(300,)

array([[0.57518554]], dtype=float32)

.

Unfortunately, the model is unable to infer vectors for unfamiliar words. This is one limitation of Word2Vec: if this limitation matters to you, check out the FastText model.

.

try:
    vec_cameroon = wv['cameroon']
except KeyError:
    print("The word 'cameroon' does not appear in this model")

>>>The word 'cameroon' does not appear in this model


.

Reference:

https://radimrehurek.com/gensim/auto_examples/tutorials/run_word2vec.html


Read More