try:
# শুধুমাত্র টেন্সর-ফ্লো ২.x ব্যবহার করবো
%tensorflow_version 2.x
except Exception:
pass
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
TensorFlow 2.x selected.
embedding_layer = layers.Embedding(1000, 5)
result = embedding_layer(tf.constant([1,2,3]))
result.numpy()
array([[-0.03846053, -0.00674887, -0.01975296, -0.02325729, 0.04202225], [ 0.02986335, 0.01062097, -0.03452694, -0.0296132 , 0.00191165], [ 0.02632796, -0.04222443, -0.03406482, -0.048172 , -0.01869417]], dtype=float32)
result = embedding_layer(tf.constant([১,২,৩]))
result.numpy()
File "<ipython-input-4-db9626af6b34>", line 1 result = embedding_layer(tf.constant([১,২,৩])) ^ SyntaxError: invalid character in identifier
!pip install spacy
Requirement already satisfied: spacy in /usr/local/lib/python3.6/dist-packages (2.1.8) Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /usr/local/lib/python3.6/dist-packages (from spacy) (1.0.2) Requirement already satisfied: requests<3.0.0,>=2.13.0 in /usr/local/lib/python3.6/dist-packages (from spacy) (2.21.0) Requirement already satisfied: thinc<7.1.0,>=7.0.8 in /usr/local/lib/python3.6/dist-packages (from spacy) (7.0.8) Requirement already satisfied: srsly<1.1.0,>=0.0.6 in /usr/local/lib/python3.6/dist-packages (from spacy) (0.1.0) Requirement already satisfied: plac<1.0.0,>=0.9.6 in /usr/local/lib/python3.6/dist-packages (from spacy) (0.9.6) Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from spacy) (2.0.2) Requirement already satisfied: wasabi<1.1.0,>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from spacy) (0.2.2) Requirement already satisfied: preshed<2.1.0,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from spacy) (2.0.1) Requirement already satisfied: blis<0.3.0,>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from spacy) (0.2.4) Requirement already satisfied: numpy>=1.15.0 in /tensorflow-2.0.0/python3.6 (from spacy) (1.17.3) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy) (3.0.4) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy) (2019.9.11) Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy) (1.24.3) Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy) (2.8) Requirement already satisfied: tqdm<5.0.0,>=4.10.0 in /usr/local/lib/python3.6/dist-packages (from thinc<7.1.0,>=7.0.8->spacy) (4.28.1)
!python -m spacy download bn_core_news_sm
✘ No compatible model found for 'bn_core_news_sm' (spaCy v2.1.8).
pip install https://github.com/banglakit/spacy-models/releases/download/bn_core_news_sm-2.0.0/bn_core_news_sm-2.0.0.tar.gz
Collecting https://github.com/banglakit/spacy-models/releases/download/bn_core_news_sm-2.0.0/bn_core_news_sm-2.0.0.tar.gz Downloading https://github.com/banglakit/spacy-models/releases/download/bn_core_news_sm-2.0.0/bn_core_news_sm-2.0.0.tar.gz (40.5MB) |████████████████████████████████| 40.5MB 223kB/s Requirement already satisfied: spacy>=>=2.0.12 in /usr/local/lib/python3.6/dist-packages (from bn-core-news-sm==2.0.0) (2.1.8) Requirement already satisfied: wasabi<1.1.0,>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (0.2.2) Requirement already satisfied: thinc<7.1.0,>=7.0.8 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (7.0.8) Requirement already satisfied: blis<0.3.0,>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (0.2.4) Requirement already satisfied: numpy>=1.15.0 in /tensorflow-2.0.0/python3.6 (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (1.17.3) Requirement already satisfied: plac<1.0.0,>=0.9.6 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (0.9.6) Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (2.0.2) Requirement already satisfied: preshed<2.1.0,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (2.0.1) Requirement already satisfied: requests<3.0.0,>=2.13.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (2.21.0) Requirement already satisfied: srsly<1.1.0,>=0.0.6 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (0.1.0) Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (1.0.2) Requirement already satisfied: tqdm<5.0.0,>=4.10.0 in /usr/local/lib/python3.6/dist-packages (from thinc<7.1.0,>=7.0.8->spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (4.28.1) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (3.0.4) Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (2.8) Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (1.24.3) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3.0.0,>=2.13.0->spacy>=>=2.0.12->bn-core-news-sm==2.0.0) (2019.9.11) Building wheels for collected packages: bn-core-news-sm Building wheel for bn-core-news-sm (setup.py) ... done Created wheel for bn-core-news-sm: filename=bn_core_news_sm-2.0.0-cp36-none-any.whl size=41254297 sha256=99fcea737cd7f45d9aeed8e4be6bb94237c779869ef398c0da06d342c5e32384 Stored in directory: /root/.cache/pip/wheels/92/ef/60/567e70071236fd8535ae8aa080933500dc0a0455bdc0287e4d Successfully built bn-core-news-sm Installing collected packages: bn-core-news-sm Successfully installed bn-core-news-sm-2.0.0
import spacy
import bn_core_news_sm
nlp = bn_core_news_sm.load()
doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?')
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-14-eba6f3de64c8> in <module>() 2 import bn_core_news_sm 3 ----> 4 nlp = bn_core_news_sm.load() 5 doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?') /usr/local/lib/python3.6/dist-packages/bn_core_news_sm/__init__.py in load(**overrides) 47 48 def load(**overrides): ---> 49 lang = load_model_from_init_py(__file__, **overrides) 50 lang.factories['sbd'] = lambda nlp, **cfg: SentenceSegmenter(nlp.vocab, **cfg) 51 lang.factories['sentencizer'] = lambda nlp, **cfg: SentenceSegmenter(nlp.vocab, **cfg) /usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model_from_init_py(init_file, **overrides) 194 if not model_path.exists(): 195 raise IOError(Errors.E052.format(path=path2str(data_path))) --> 196 return load_model_from_path(data_path, meta, **overrides) 197 198 /usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model_from_path(model_path, meta, **overrides) 175 if name not in disable: 176 config = meta.get("pipeline_args", {}).get(name, {}) --> 177 component = nlp.create_pipe(name, config=config) 178 nlp.add_pipe(component, name=name) 179 return nlp.from_disk(model_path) /usr/local/lib/python3.6/dist-packages/spacy/language.py in create_pipe(self, name, config) 261 if name not in self.factories: 262 if name == "sbd": --> 263 raise KeyError(Errors.E108.format(name=name)) 264 else: 265 raise KeyError(Errors.E002.format(name=name)) KeyError: "[E108] As of spaCy v2.1, the pipe name `sbd` has been deprecated in favor of the pipe name `sentencizer`, which does the same thing. For example, use `nlp.create_pipeline('sentencizer')`"
import spacy
import bn_core_news_sm
nlp = bn_core_news_sm.load()
doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?')
# Create list of word tokens
token_list = []
for token in doc:
token_list.append(token.text)
print(token_list)
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-11-30dfcdec090f> in <module>() 2 import bn_core_news_sm 3 ----> 4 nlp = bn_core_news_sm.load() 5 doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?') 6 /usr/local/lib/python3.6/dist-packages/bn_core_news_sm/__init__.py in load(**overrides) 47 48 def load(**overrides): ---> 49 lang = load_model_from_init_py(__file__, **overrides) 50 lang.factories['sbd'] = lambda nlp, **cfg: SentenceSegmenter(nlp.vocab, **cfg) 51 lang.factories['sentencizer'] = lambda nlp, **cfg: SentenceSegmenter(nlp.vocab, **cfg) /usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model_from_init_py(init_file, **overrides) 194 if not model_path.exists(): 195 raise IOError(Errors.E052.format(path=path2str(data_path))) --> 196 return load_model_from_path(data_path, meta, **overrides) 197 198 /usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model_from_path(model_path, meta, **overrides) 175 if name not in disable: 176 config = meta.get("pipeline_args", {}).get(name, {}) --> 177 component = nlp.create_pipe(name, config=config) 178 nlp.add_pipe(component, name=name) 179 return nlp.from_disk(model_path) /usr/local/lib/python3.6/dist-packages/spacy/language.py in create_pipe(self, name, config) 261 if name not in self.factories: 262 if name == "sbd": --> 263 raise KeyError(Errors.E108.format(name=name)) 264 else: 265 raise KeyError(Errors.E002.format(name=name)) KeyError: "[E108] As of spaCy v2.1, the pipe name `sbd` has been deprecated in favor of the pipe name `sentencizer`, which does the same thing. For example, use `nlp.create_pipeline('sentencizer')`"
import spacy
nlp = spacy.load("bn_core_news_sm")
doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?')
for token in doc:
print(token.text, token.pos_, token.dep_)
--------------------------------------------------------------------------- OSError Traceback (most recent call last) <ipython-input-13-b2b873720094> in <module>() 1 import spacy 2 ----> 3 nlp = spacy.load("bn_core_news_sm") 4 doc = nlp(u'আমি বাংলায় গান গাই। তুমি কি গাও?') 5 for token in doc: /usr/local/lib/python3.6/dist-packages/spacy/__init__.py in load(name, **overrides) 25 if depr_path not in (True, False, None): 26 deprecation_warning(Warnings.W001.format(path=depr_path)) ---> 27 return util.load_model(name, **overrides) 28 29 /usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model(name, **overrides) 137 elif hasattr(name, "exists"): # Path or Path-like to model data 138 return load_model_from_path(name, **overrides) --> 139 raise IOError(Errors.E050.format(name=name)) 140 141 OSError: [E050] Can't find model 'bn_core_news_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.