Kernel Died when running Neuralcoref - jupyter-notebook

I am trying to install neuralcoref and following the instructions given here.
I created a jupyter notebook and try to run the following code.
# Load your usual SpaCy model (one of SpaCy English models)
import spacy
nlp = spacy.load('en')
# Add neural coref to SpaCy's pipe
import neuralcoref
neuralcoref.add_to_pipe(nlp)
# You're done. You can now use NeuralCoref as you usually manipulate a SpaCy
document annotations.
doc = nlp(u'My sister has a dog. She loves him.')
doc._.has_coref
doc._.coref_clusters
I get an error message from the jupyter, that kernel died. Even I try to run in the in a python file but still its not working.
O.S - Windows 10
RAM : 16GB
Note: I did try out to updating numpy but still it didn't worked.
Can anyone help me with that. Appreciate your time.
Thanks

As per here: https://github.com/huggingface/neuralcoref/issues/189.
You can get it to work fine if you downgrade Spacy to 2.1.0.
pip uninstall spacy
pip uninstall neuralcoref
pip install spacy==2.1.0
pip install neuralcoref --no-binary neuralcoref
Has worked for others, including myself. Notebook now runs fine.

There is no need to downgrade spacy at all. Build from source, because neuralcoref installed with pip is built against spacy==2.1.0.
Proof:
Build:
git clone https://github.com/huggingface/neuralcoref.git
cd neuralcoref
pip install -r requirements.txt # correct for the desired versions of Cython and SpaCy
python setup.py install
Test:
import spacy
import neuralcoref
nlp = spacy.load('en_core_web_md')
neuralcoref.add_to_pipe(nlp)
print(spacy.__version__)
doc = nlp(u'My sister has a dog. She loves him.')
print(doc._.has_coref)
print(doc._.coref_clusters)
2.3.2
True
[My sister: [My sister, She], a dog: [a dog, him]]

Related

Azure Machine Learning notebooks: ModuleNotFound error

I'm working through a Python exercise using Azure Machine Learning notebooks. I'm unable to import torch even after !pip install torch.
Notebook says Requirement already satisfied, then errors out with:
!pip install torch
import torch
data = torch.tensor(encode(text), dtype=torch.long)
print(data.shape, data.dtype)
print(data[:100])
4 sec
ModuleNotFoundError: No module named 'torch'
Requirement already satisfied: torch in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (1.12.0)
Requirement already satisfied: typing-extensions in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (from torch) (4.4.0)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [22], in <cell line: 4>()
1 # Encode the entire dataset and store it into a torch.Tensor
3 get_ipython().system('pip install torch')
----> 4 import torch
5 data = torch.tensor(encode(text), dtype=torch.long)
6 print(data.shape, data.dtype)
ModuleNotFoundError: No module named 'torch'
I opened up a terminal in Azure ML Studio and tried pip install torch too, same Requirement already satisfied message showed.
How do I get torch (and any other Python modules where this occurs) working in AML notebooks?
I've found creating environments and installing packages through the terminal to be a much more reliable experience than doing it from an AML notebook.
I suggest using one of the provided terminals (either the one available in the compute instance's details, or the one available in JupyterLab) to create a new conda environment which you can customize to your liking.
Something like:
conda create -n my_tutorial python=3.10
conda activate my_tutorial
pip install --user ipykernel
python -m ipykernel install --user --name=my_tutorial
# Do a complete install of PyTorch, take a look at the available versions here https://pytorch.org/get-started/previous-versions/
conda install pytorch=1.13 torchvision=0.14 torchaudio=0.13 pytorch-cuda=11.7 -c pytorch -c nvidia -y
Afterwards, just make sure your notebooks use the my_tutorial kernel and you should be good to go. Whenever you want to pip install something new, just go back to the terminal, activate your kernel, and install the thing, then it should be available in your notebooks as well.
The issue was lined out in the docs here. Don't use !pip within the notebook. Instead use %pip.

AttributeError: module 'scipy.sparse' has no attribute 'coo_array'

Getting this error in my Jupyter Notebook
What would be the best way to fix this utilizing conda instead of pip
I've attempted conda upgrade --all and that didnt seem to work
The scipy.sparse.*_array functions were introduced with v1.8. The networkx package started requiring scipy >=1.8 with v2.7. So, either upgrade SciPy
conda install 'scipy>=1.8'
or downgrade NetworkX:
conda install 'networkx<2.7'
Part of the issue here is that, at the recommendation of a networkx developer, Conda Forge stopped explicitly requiring scipy as a dependency of networkx, and therefore there is no longer any constraint. I opened an issue on the feedstock to revisit coinstallation constraints (run_constrained specifications).
As mentioned in this Github comment, I was trying to calculate the page rank (networkx.pagerank) of a graph on Google Colab when I encountered the same error. After executing the following code, the issue was resolved for me:
!pip install --upgrade scipy networkx
A Side Note: pip install refers to installing packages and leave the package as-is if it is already installed. But the --upgrade flag instructs pip to uninstall anything which is being upgraded/replaced. For more info on this, refer this official doc.
I encountered similar error
I could solve it by installing these versions of newtorkx and scipy:
!pip install 'networkx<2.7'
!pip install 'scipy>=1.8'

module 'torch.jit' has no attribute 'unused'

I am a student trying to get my hands into facial recognition using Ultra96 and I am having troubles running my program.
I have tried to install nightly version into my Ultra96 however, it does not solve my problem. The current OS is pynq 2.6 which is Linux and it is using jupyter notebook to run the codes.
Please offer me some guidance!
use torchvision 0.4.0:
pip uninstall torchvision
pip install torchvision==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html
This will work for sure
EDIT : if above cmd wont work , use this pip install torchvision==0.4.0

spacyr installation on R: /usr/local/bin/python is not a python executable

I used this instruction to install spacyr on RStudio (mac os)
I have both python 2 and 3 so I run
library(spacyr)
spacy_initialize(python_executable = "/usr/local/bin/python")
It returns an error:
Error in check_spacy_model(python_executable, model) :
/usr/local/bin/python is not a python executable
Any advice on how to fix it? Thanks.
I spent a lot of time figuring out this issue for myself. For me the problem was I had installed spacy using conda rather than pip so it was unable to setup symlink.
uninstall spacyr
uninstall spacy from python(if you have installed using conda)
Install spacy with pip only
Install the latest version of spacyr from github.

How to install Tensorflow for R

I had Tensorflow installed with Anaconda. Now I want use it in R and I need to reinstall Tensorflow, because the note here
NOTE: You should NOT install TensorFlow with Anaconda as there are
issues with the way Anaconda builds the python shared library that
prevent dynamic linking from R.
I already tried to uninstall from Anaconda and install with pip but its came to the same place in anaconda directory. Tesorflow is working from terminal but in R shows Error: Command failed (1)
Anybody can help me to how I can solve the problem? Should I uninstall anaconda and install Tensorflow using pip?
You have several options on what to do. Probably the cleanest one is to install a system-wide python (if not installed yet) and then create a virtual environment. This basically takes your system python binaries and moves them to its own compartment where everythign is isolated from the rest, incl. anaconda. Once you are inside an activated virtual environment you can install all the necessary Python appendages for TensorFlow. Once that is done, make sure you set up a correct environmental PATH for TensorFlow from where R can reach it:
Sys.setenv(TENSORFLOW_PYTHON="/path/to/virtualenv/python/binary")
devtools::install_github("rstudio/tensorflow")
Example of the path to where you installed the virtual environment project would be, I think, something like ~/minion/medvedi/venv_medvedi/bin/python.
This is no longer an issue, the documentation was updated too.
See here:
https://github.com/rstudio/tensorflow/commit/4e1e11d6ba2fe7efe1a03356f96172dbf8db365e
With the help of Keras, we can install the TensorFlow package in R.
install_keras()
library(keras)
devtools::install_github("rstudio/keras")
install_tensorflow(package_url = "https://pypi.python.org/packages/b8/d6/af3d52dd52150ec4a6ceb7788bfeb2f62ecb6aa2d1172211c4db39b349a2/tensorflow-1.3.0rc0-cp27-cp27mu-manylinux1_x86_64.whl#md5=1cf77a2360ae2e38dd3578618eacc03b")
library(tensorflow)
Keras is a high-level neural network API for deep learning from TensorFlow Google.
my suggestion is to install anaconda and create an environment called "r-reticulate".
you can do it using anaconda navigator or
reticulate::conda_create(envname = "r-reticulate")
then to check that env detected by reticulate, use reticulate::conda_python().it must return directory of python.exe for your env.
after that you can install tensorflow by install_tensorflow(). [not working in my case]
so I install the tesnorflow from CMD.
follow these steps:
open the cmd :]
activate the r-reticulate env using conda activate r-reticulate (you may need your directory to conda directory if you did not add conda to your PATH)
use : conda install -c anaconda tensorflow
now in R, you can use TensorFlow.
for installing Keras, you can use pip install Keras. [i tried install_keras() function after the installation of tensorflow, but it ruined my TensorFlow installation also]
Eventually I found the best and fast method to do it in R:
devtools::install_github("rstudio/keras")
library(keras)
install_keras(method = "conda")
install_keras(tensorflow = "gpu")
tensorflow::install_tensorflow()

Resources