Skip to content

Instantly share code, notes, and snippets.

@joelgrus
Last active February 3, 2023 12:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelgrus/8e994d908816ff91cd3df3602389dc0b to your computer and use it in GitHub Desktop.
Save joelgrus/8e994d908816ff91cd3df3602389dc0b to your computer and use it in GitHub Desktop.

Installing AllenNLP on Windows

This is not guaranteed to work, but it might be worth trying. (If it doesn't work, it's doubtful I can help you any further than this.)

  1. Make sure you have a lot of hard drive space
  2. Install Anaconda and create a python 3.7 environment
  3. Follow the instructions at pytorch.org to install the appropriate pytorch
  4. Install the Visual C++ Build Tools https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
  5. install cython: conda install cython
  6. pip install allennlp==0.6.0
  7. go into requirements.txt and comment out the jsonnet requirement
  8. pip install -r requirements.txt

With these changes, I was able to get some things to work:

In [1]: from allennlp.commands.elmo import ElmoEmbedder
c:\programdata\anaconda3\envs\python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
c:\programdata\anaconda3\envs\python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192, got 176
  return f(*args, **kwds)
c:\programdata\anaconda3\envs\python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
c:\programdata\anaconda3\envs\python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192, got 176
  return f(*args, **kwds)

In [2]: embedder = ElmoEmbedder()

In [3]: embedder.embed_sentence(['I', 'am', 'running', 'on', 'Windows', '!'])
Out[3]:
array([[[ 0.6922717 , -0.32613146,  0.22827497, ...,  0.17574835,
          0.26598698, -0.10131979],
        [ 0.47849345, -0.40329027, -0.2701909 , ...,  0.4731399 ,
          0.06390641, -0.24718216],
        [ 0.14722444, -0.47922066, -0.67276937, ..., -0.11418007,
         -0.08979627,  0.39328256],
        [ 0.04337816,  0.13920836, -0.41552842, ..., -0.30192983,
          0.0800785 ,  0.10883451],
        [ 0.27818012, -0.993336  ,  0.45494545, ...,  0.51757586,
         -0.27050474,  0.14971495],
        [-1.3351283 ,  0.629655  , -1.465039  , ...,  0.02952403,
          0.6431519 ,  0.83388734]],

       [[-1.1051465 , -0.40921745, -0.43645096, ..., -0.18907748,
         -0.12834789,  0.13978648],
        [-0.49249613, -0.43753132, -0.4216873 , ...,  0.11542958,
          0.5331211 , -0.22311366],
        [ 0.6008519 , -0.3917898 ,  0.19312546, ..., -0.47283816,
         -0.42680824, -0.6539775 ],
        [ 0.26335433,  0.1473494 , -0.6684478 , ..., -1.117649  ,
         -0.9062052 , -0.5023282 ],
        [-0.5850049 ,  0.7062184 ,  0.396958  , ...,  0.6596563 ,
         -1.0240142 ,  0.07517085],
        [-1.260252  , -0.4782271 , -0.0692471 , ...,  0.20073146,
          0.10832265, -0.19125694]],

       [[-3.263432  , -0.9447758 , -0.31986552, ..., -1.4083313 ,
         -0.8858242 , -0.16667527],
        [-1.3764668 , -1.2219774 , -0.6067575 , ..., -0.18251151,
          0.26231462, -0.41164684],
        [ 0.29532486, -0.6136186 ,  0.7191876 , ..., -0.7471914 ,
         -0.9818682 , -0.5730877 ],
        [-0.12740043, -0.7731147 , -1.2073629 , ..., -3.2957711 ,
         -1.3318675 , -0.88693726],
        [-1.080706  ,  0.943465  ,  1.061666  , ...,  0.02399278,
         -1.4294988 , -0.35563016],
        [-1.2895848 ,  0.02143741, -0.48171747, ...,  0.30947244,
          0.3493979 ,  0.06589803]]], dtype=float32)

In [4]:

However, the unit tests fail spectacularly, for filesystem-related reasons that I don't have the time to investigate.

If you are able to make this work for training/evaluating a model, please let me/us know.

@brandonmburroughs
Copy link

Hey Joel. Thanks so much for providing these instructions!

This worked for me on a Windows 10 laptop with CUDA 9 and git bash! I followed your instructions (though I installed allennlp==0.7.2) and everything went smoothly. I didn't have to comment out the jsonnet requirement since y'all added the Windows exclusion.

After this worked, I was also able to install an environment using this environment.yml. At this point, I already had the Visual C++ Build Tools installed but that would have been the only manual step.

Btw, I'm not doing too much with it yet other than following the LSTM PoS tagger tutorial, but all of that is working flawlessly. I'll let you know if I use it in the future. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment