[PYTHON] Execute Language Interpretability Tool (LIT) in Windows 10 environment (1. Environment construction)

Google Research has open sourced the Language Interpretability Tool (LIT) platform for understanding and visualizing NLP models. I would like to try it out.

All 3 articles are planned. ** 1. Execute Language Interpretability Tool (LIT) in Windows 10 environment (1. Environment construction) [This article] ** 2. Execute Language Interpretability Tool (LIT) in Windows 10 environment (2. Function check) 3. Run Language Interpretability Tool (LIT) in Windows 10 environment (3. Original model)

In this article, we will describe the ** environment construction procedure ** in the ** Windows 10 Home environment **.

table of contents

  1. [What is LIT](What is # 1-lit)
  2. [Install Docker Desktop for Windows](Install # 2-docker-desktop-for-windows)
  3. [Run LIT sample program](# 3-Run lit sample program)
  4. [Finally](# 4-Finally)

1. What is LIT?

The Language Interpretability Tool (LIT) is a tool for understanding and visualizing NLP models. LIT.png

The browser-based UI has the following features: (Excerpt from the paper) paper.png

If you want to know more details, please refer to the following.

--The paper is here --GitHub is here --Click here for user guide (https://github.com/PAIR-code/lit/blob/main/docs/user_guide.md)

I feel like I can't say anything unless I touch this kind of tool system, so I decided to try it out.

2. Install Docker Desktop for Windows

This time, in order to set up a server using Docker, install ** Docker Desktop for Windows ** in ** Windows 10 Home environment **.

2-1. Docker ID creation

2-2. Windows 10 Home Update

When I tried to install Docker Desktop for Windows, I got the following error in my environment.

Docker Desktop requires Windows 10 Pro/Enterprise (15063+) or Windows 10 Home (19018+).

It looks like ** Windows needs to be updated ** before installation.

Follow the steps below to update Windows 10 Home. ** Windows Start Menu → Settings → Run Update from Windows Update ** It didn't end even after waiting for about an hour, but it ended when I slept and woke up.

When I saw it in the morning, it was safely upgraded to the following version. windows_update.png

2-3. Installing Docker Desktop for Windows

I will actually install it. Click ** Download for Windows (stable) ** from the URL below to download the installer. https://www.docker.com/products/docker-desktop download.png

When I double-clicked on the installer and followed the steps, I ran into the following error: It looks like ** I need to update the Linux kernel **. Click the link as instructed.

wls2.png

You will be taken to the MS documentation, so ** download the Linux kernel update package **. wls2_2.png

Run the downloaded ** wsl_update_x64.msi **. It ends in an instant. wls2_3.png

After that, go back to the procedure and finish all the steps ** Docker Desktop for Windows installation is finished **.

reference

Articles of people who hit a similar error https://tech.guitarrapc.com/entry/2020/04/21/034236

Difference between "Docker Toolbox" and "Docker Desktop for Windows" https://fumidzuki.com/knowledge/1033/

3. Run the LIT sample program

Finally, by executing the sample program ** quickstart_sst_demo.py **, set up a server on Docker and set up a server. You will see it in your browser from the host side.

In LIT README, the environment is created with conda, so Prepare the virtual environment and then configure the settings so that the host can access the server.

3-1. Change the memory allocation of WSL2

Before you start preparing the virtual environment, make a ** change the memory allocation of WSL2 **. If you don't do this, by default ** 80% of your PC's memory will be allocated **, and in my case it's a 16GB PC, so about 13GB of memory will be allocated.

The procedure is simple: create a **. Wslconfig ** file in **% UserProfile% ** on the host side and specify the memory allocation. 3GB was enough to run the demo.

~/.wslconfig


[wsl2]
memory=3GB

3-2. Preparation of virtual environment

** Pull and launch the Docker container containing Anaconda. ** ** From the command line: (The container name ** lit_env ** can be changed arbitrarily.) Reference: https://hub.docker.com/r/continuumio/anaconda3

docker pull continuumio/anaconda3
docker run -it --name lit_env continuumio/anaconda3 /bin/bash

When you start the Docker container, the default virtual environment name ** base is activated **.

Next, ** install the required packages **. Basically, proceed according to the README procedure, but if it is left as it is, an error will occur, so I have changed it a little. Reference: https://github.com/pair-code/lit/issues Reference: https://github.com/yarnpkg/yarn/issues/7329

git clone https://github.com/PAIR-code/lit.git ~/lit

# Set up Python environment
cd ~/lit
conda env create -f environment.yml
conda activate lit-nlp
conda install cudnn cupti  # optional, for GPU support
conda install -c pytorch pytorch  # optional, for PyTorch

# Build the frontend
cd ~/lit/lit_nlp/client
######I don't have yarn so I will install it
#Simply"apt-get install yarn"If so, an error will occur after that, so execute the following
curl https://deb.nodesource.com/setup_12.x | bash
curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install -y nodejs yarn postgresql-client
######
yarn && yarn build

The installation of the package etc. is completed, and the preparation of the virtual environment is completed.

3-3. Change settings to access the server from the host

All I have to do is hit the sample program, With the sample as it is **, I started a server to listen on localhost of Docker container, Since it cannot be accessed from the host **, rewrite the sample program so that the server is set up on ** 0.0.0.0. ** **

First, ** install vim **.

apt-get install vim

Run the following command to open the ** server_flags.py ** file. (If necessary, make a backup before editing.)

vi /root/lit/lit_nlp/server_flags.py

Rewrite the following part and save.

#flags.DEFINE_string('host', '127.0.0.1', 'What host address to serve on.')
flags.DEFINE_string('host', '0.0.0.0', 'What host address to serve on.')

Later, I will put in the port forwarding option and hit the ** docker run ** command, so I will save the container as an image. First, exit.

exit

Run the ** docker commit ** command and save the container named ** lit_env ** as an image. (It is saved as ** lit_env_img **, but the name is of course arbitrary.)

docker commit lit_env lit_env_img

3-4. Execution of sample program

If you follow the LIT README, you will later launch the server with **-port5432 **. .. So, execute the ** docker run ** command with the port forwarding option specified as ** port on the container side as 5432 **. (Of course, the port number on the host side is arbitrary.)

docker run -it -p 5432:5432 lit_env_img /bin/bash

Run a demo of the emotion classification task, which is a sample program. It seems that it is fine tuning about 3 epoch.

conda activate lit-nlp
cd ~/lit
python -m lit_nlp.examples.quickstart_sst_demo --port=5432

It is complete when the following message is output.

Starting Server on port 5432 You can navigate to 0.0.0.0:5432

Access the following URL from the browser on the host side.

http://127.0.0.1:5432/

You should be able to access it normally. LIT.png

This is the end of the environment construction procedure under the Windows 10 Home environment.

4. Finally

This time I changed various settings to avoid the error. As you can see from the LIT Issue, Since there have been quite a few exchanges in the past week, including the contents, There may be updates in the near future. If that happens, I think it will be easier to build an environment.

Next time, I would like to take a look at various LIT functions!

Recommended Posts

Execute Language Interpretability Tool (LIT) in Windows 10 environment (1. Environment construction)
python windows environment construction
Go language environment construction
virtualenvwrapper in windows environment
Python environment construction (Windows10 + Emacs)
Python environment construction under Windows7 environment
[Tensorflow] Tensorflow environment construction on Windows 10
Python environment construction memo on Windows 10
Anaconda python environment construction on Windows 10
Various Anaconda settings in Windows 10 environment
[Python3] Development environment construction << Windows edition >>
Ml-Agents Release 6 (0.19.0) Environment Construction Summary [Windows]
UnicodeDecodeError occurs in pip (Windows environment)
Python project environment construction procedure (for windows)
Using venv in Windows + Docker environment [Python]
Set up Pipenv in Pycharm in Windows environment
VScode environment construction (Windows10, Python, C ++, C, Git)
Building scikit-learn in Windows 10 environment using Pycharm
[Windows 10] "Deep Learning from scratch" environment construction
Python garbled in Windows + Git Bash environment
Windows + gVim + Poetry python development environment construction
Run PIFuHD in Windows + Anaconda + Git Bash environment
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Install Python 3.5.1 + numpy + scipy + α in Windows environment
[Environment construction] Dependency analysis using CaboCha in Python 2.7
Data science 100 knock (structured data processing) environment construction (Windows10)