[TFX 스터디] 2. Interactive Notebook
인공지능/Tensorflow Extended

[TFX 스터디] 2. Interactive Notebook

사실 ExampleGen을 만들때부터 Jupyter를 통해 TFX의 Interactive Notebook 기능을 사용하려 했다. Interactive Notebook이란 Notebook 환경에서 Component를 직접 실행하고 이에 대한 중간 결과를 볼 수 있는 기능을 말한다.

출처: https://blog.tensorflow.org/2019/11/introducing-tfx-interactive-notebook.html

Interactive Notebook을 사용하면 각 단계별로 데이터가 어떻게 처리되는지를 디버깅하면서 짤 수 있기 때문에 이번 프로젝트에서 사용하고자 했다. 그런데 저번 주차에 사용하지 않았는데, 그 이유가 Jupyter Notebook를 실행하는데 문제가 발생했다. 처음에는 Jupyter Notebook 서버가 열리지 않아 Jupyter를 재설치하고 서버를 켰다. 그런데 이번에는 노트북에서 ipykernel 버전이 맞지 않아 Interactive Notebook을 쓰지 못했다. 그래서 여러번 TFX를 지웠다 재설치한 지금에서야 사용할 수 있었다. 스터디 그룹에서 다른 분들은 이상없이 잘 작동한 것을 보면 내가 무언가 설치하다 버전이 꼬인 듯하다.

from tfx.orchestration.experimental.interactive.interactive_context ipmort InteractiveContext

context = InteractiveContext()

# example_gen, statistics_gen 정의 생략

# Component 실행
context.run(example_gen)
context.run(statistics_gen)

# 실행 결과 확인하기
context.show(statistics_gen.outputs['statistics'])

Interactive Notebook을 사용할 때는 반드시 Component들을 순차적으로 `context.run()`함수로 실행해야 한다. 여기서는 `statistics_gen`이 `example_gen`의 결과값을 사용하므로 `example_gen`이 먼저 실행되고 `statistics_gen`이 실행된다. 한 Component씩 실행한다면 Notebook에서는 다음과 같은 결과가 나온다.

context.run(statistics_gen)을 실행한 결과

위에 나온 결과는 Component에 어떤 값이 들어오고 어떤 값이 나왔는지를 보여준다. 아마 주로 확인할 부분이 `.component.inputs`와 `.component.outputs`일 것이다. StatisticsGen을 정의할때도 ExampleGen의 결과값을 가져와야하는데 이때 `.component.outputs`에서 어떤 key값이 어떤 데이터가 들어있는지 확인해볼 수 있다. 이렇게 한 차례씩 실행해보면서 다음 Component에서 어떤 값을 전달해야할지 볼 수 있다는게 Interactive Notebook 기능의 장점이다.

context.show()를 실행한 결과

이렇게 나온 결과를 `context.show()`함수로 보면 다음과 같은 UI가 뜬다. 사진에는 나오지 못했지만 train 데이터셋과 eval 데이터셋이 따로 나오는 것을 확인할 수 있다. 앞으로도 Interactive Notebook을 통해 각 Component가 어떻게 데이터를 내보내는지 확인해 볼 것이다.

다음주에는 아마 Transform을 건드려 볼 것이다. 최근에 HyperCLOVA에서 발표한 자료중에 한국어 토크나이징과 관련된 발표를 발견해 이를 적용해 볼 것이다.