What do I do wrong when install OpenKiwi? - python

I tried to work with OpenKiwi to Anaconda3
and after installation (pip install openkiwi)
I execute following code
(I do this because I want to create openkiwi vocabulary) :
import warnings
from collections import defaultdict
import torchtext
from kiwi.constants import PAD, START, STOP, UNALIGNED, UNK, UNK_ID
And than I have an error message:
ImportError Traceback (most recent call last)
<ipython-input-6-ea850b280bef> in <module>
4 import torchtext
5
----> 6 from kiwi.constants import PAD, START, STOP, UNALIGNED, UNK, UNK_ID
ImportError: cannot import name 'UNK_ID' from 'kiwi.constants' (C:\Users\Mike\anaconda3\lib\site-packages\kiwi\constants.py)
Anaconda3 has following versions: >!
pytorch-lightning: 1.7.6
pytorch-nlp: 0.5.0
torch: 1.4.0
torch metrics 0.9.3
torch: text 0.13.1
transformers: 3.5.1

UNK_ID is no longer a constant in the latest version of OpenKiwi. That second link shows some code targeting version 1.4 or so, while OpenKiwi is at version 2.1 now. Just drop the UNK_ID from the import line, and replace the one in the code with 0.

Related

Transformers AutoModelForCasualLM cannot be imported

I am trying to follow this article to use the AutoModelForCasualLM from transformers to generate text with bloom. But I keep getting an error saying that python cannot AutoModelForCasualLM from transformers. I have tried multiple computers and multiple versions of transformers but I always get the following error. (Traceback from latest version of transformers)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[28], line 1
----> 1 from transformers import AutoTokenizer, AutoModelForCasualLM, BloomConfig
2 from transformers.models.lboom.modeling_bloom import BloomBlock, build_alibi_tensor
ImportError: cannot import name 'AutoModelForCasualLM' from 'transformers' (/mnt/MLDr/venv/lib/python3.10/site-packages/transformers/__init__.py)
code snippet from where the error occurs (first ~10 lines):
import os
import torch
import torch.nn as nn
from collections import OrderedDict
def get_state_dict(shard_num, prefix=None):
d = torch.load(os.path.join(model_path, f"pytorch_model_{shard_num:05d}-of-00072.bin"))
return d if prefix is None else OrderedDict((k.replace(prefix, ''), v) for k, v in d.items())
from transformers import AutoTokenizer, AutoModelForCasualLM, BloomConfig
from transformers.models.lboom.modeling_bloom import BloomBlock, build_alibi_tensor
model = "./bloom"
config = BloomConfig.from_pretrained(model_path)
device = 'cpu'
transformers-cli env results:
transformers version: 4.25.1
Platform: Linux-5.15.0-58-generic-x86_64-with-glibc2.35
Python version: 3.10.6
Huggingface_hub version: 0.11.1
PyTorch version (GPU?): 1.13.1+cu117 (False)
Tensorflow version (GPU?): 2.11.0 (False)
Flax version (CPU?/GPU?/TPU?): not installed (NA)
Jax version: not installed
JaxLib version: not installed
Using GPU in script?: <fill in>
Using distributed or parallel set-up in script?: <fill in>

Can't from PIL import Image?

I have tried to install pillow version 7.0.0 but get the following error below. Please suggest a solution.
ImportError Traceback (most recent call last)
<ipython-input-32-b7f01c2f8cfe> in <module>
----> 1 from PIL import Image
~\Anaconda3\envs\streamlined\lib\site-packages\PIL\Image.py in <module>
42 # PILLOW_VERSION was removed in Pillow 7.0.0.
43 # Use __version__ instead.
---> 44 from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
45 from ._binary import i8, i32le
46 from ._util import deferred_error, isPath
ImportError: cannot import name 'UnidentifiedImageError' from 'PIL' (unknown location)
This looks like a library that you are using, or that is interfacing with PIL/Pillow was built for a previous version, so you either need to update the library/code calling PIL/Pillow, or install the version of Pillow that your library/code is written for.
Example of how to install pillow version 5.0.0
$ pip install pillow==5.0.0

Getting numpy error when using azureml-sdk

hy I followed the installation instructions here
and installed with
pip install --upgrade azureml-sdk[notebooks,automl] azureml-dataprep --ignore-installed PyYAML
It seem to work but a simple
import azureml.core
azureml.core.VERSION
Throws me a numpy error
> AttributeError Traceback (most recent call
> last) <ipython-input-3-08b704cd5542> in <module>
> ----> 1 import azureml.core
> 2 azureml.core.VERSION
c:\users\werth\appdata\local\continuum\anaconda3\envs\azuresdk\lib\site-packages\azureml\core\__init__.py in <module>
4
5 """Setup file for core package."""
----> 6 from azureml.core.workspace import Workspace
7 from azureml.core.experiment import Experiment
8 from azureml.core.runconfig import RunConfiguration
... I did not include the total traceback as it is apparently a Azure import problem.
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
It seems that the workspace has a problem. But I cannot think why. The Notebook is in a subfolder of the working directory. Numpy is installed.
If you would have an idea I would be thankfull.
Hi greatest Floridaman,
the answer is simple. During the installation of the azureml-train-automl 1.0.8 package, the numpy package needs to be maximum at version 1.15.0
So just downgrade numpy to that version
conda install numpy=1.15.0

sonnet import fails on: 'from graphs import Sonnet'

Trying to run some github code which imports 'sonnet' which seems to import other packages from 'graphs'. I get:
----> 9 import sonnet as snt
~\Anaconda3\lib\site-packages\sonnet\__init__.py in <module>()
1 __version__ = '0.1.6'
----> 2 from graphs import Sonnet, D3Graph, MatplotGraph
ImportError: cannot import name 'Sonnet'
I've explicitly installed and imported 'graphs', but failed with the same error when explicitly tried to:
----> 1 from graphs import Sonnet
ImportError: cannot import name 'Sonnet'
Any advice?
Environment: Jupyter Notebook, python 3.6.5, Anaconda, windows
Try this.
pip uninstall sonnet;
pip install dm-sonnet

Trying to plot an image in python (using scipy and numpy)

I'm trying to run this code:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-19
so I change it to this one:
and then I got this:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-47
What's wrong? I'm a newbie, and fyi, I'm only have anaconda installed to my Python 3.6.6 .
Regards,
--
and in code:
from skimage import data
photo_data = misc.imageio('./wifire/sd-3layers.jpg')
type(photo_data)
and i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-c8186ae7b8e9> in <module>()
1 from skimage import data
2
----> 3 photo_data = misc.imageio('./wifire/sd-3layers.jpg')
4
5 type(photo_data)
AttributeError: module 'scipy.misc' has no attribute 'imageio'
So I change it to:
You have to import imageio. You might have to install the library if you don't have it yet (on your terminal):
pip install imageio
(If you don't have pip install yet, you can do on your terminal sudo easy_install pip, see here: How do I install pip on macOS or OS X?)
And then your code to use read the image with imageio:
import imageio
im = imageio.imread('./wifire/sd-3layers.jpg')
type(im)
To display your image, you can use visvis library (https://imageio.readthedocs.io/en/stable/examples.html). Then you total code would be:
import imageio
import visvis as vv
im = imageio.imread('./wifire/sd-3layers.jpg')
vv.imshow(im)

Categories

Resources