This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.6" | |
| services: | |
| producer: | |
| build: | |
| context: . | |
| dockerfile: Dockerfile-producer | |
| networks: | |
| - outside | |
| container_name: producer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM python:3.9-slim-buster as builder | |
| LABEL MAINTAINER "Khaerul Umam <khaerulumam42@gmail.com>" | |
| LABEL DESCRIPTION "consumer" | |
| RUN apt-get update && apt-get upgrade -y \ | |
| && apt-get install -y python3 python3-pip \ | |
| python3-setuptools gfortran liblapack-dev liblapack3 nano \ | |
| default-libmysqlclient-dev\ | |
| supervisor locales \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| from json import loads | |
| from kafka import KafkaConsumer | |
| logging.basicConfig(level=logging.WARNING) | |
| consumer = KafkaConsumer( | |
| "tutorial_topic", | |
| bootstrap_servers=["kafka:9092"], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from kafka.admin import KafkaAdminClient, NewTopic | |
| import json | |
| config_file = "kafka_topics_config.json" | |
| with open(config_file, "r") as f: | |
| config = json.load(f) | |
| client_id = config["client_id"] | |
| bootstrap_servers = config["bootstrap_servers"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "context": "Setelah menolak supervisi dari PBB, pemerintah Indonesia melaksanakan \"Act of Free Choice\" (Aksi Pilihan Bebas) di Irian Jaya pada 1969 di mana 1.025 wakil kepala-kepala daerah Irian dipilih dan kemudian diberikan latihan dalam bahasa Indonesia. Mereka secara konsensus akhirnya memilih bergabung dengan Indonesia. Sebuah resolusi Sidang Umum PBB kemudian memastikan perpindahan kekuasaan kepada Indonesia. Penolakan terhadap pemerintahan Indonesia menimbulkan aktivitas-aktivitas gerilya berskala kecil pada tahun-tahun berikutnya setelah perpindahan kekuasaan tersebut. Dalam atmosfer yang lebih terbuka setelah 1998, pernyataan-pernyataan yang lebih eksplisit yang menginginkan kemerdekaan dari Indonesia telah muncul.", | |
| "qas": [ | |
| { | |
| "id": "c0ef321b6cae1037395190cbc16283e83fc43169", | |
| "question": "Apa yang dilakukan oleh pemerintah Indonesia setelah menolak supervisi dari PBB", | |
| "answers": [ | |
| { | |
| "answer_start": 92, | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.most_similar(positive=['pria', 'ratu'], negative=['wanita']) | |
| # akan menampikan hasil | |
| # [('raja', 0.6960218548774719), | |
| # ('penobatan', 0.679295539855957), | |
| # ('ratunya', 0.6650367379188538), | |
| # ('penobatannya', 0.6561974287033081), | |
| # ('dayangnya', 0.650506854057312), | |
| # ('dayang', 0.6348780393600464), | |
| # ('ringga', 0.6338657736778259), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gensim.models import KeyedVectors | |
| model_name = 'model_id_full_skipgram.vec' | |
| model = KeyedVectors.load_word2vec_format(model_name) | |
| # 5 top similar words | |
| model.most_similar("fisika")[:5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !./fasttext skipgram -input wiki_id.txt -output wiki_skipgram |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from gensim.corpora import WikiCorpus | |
| def make_corpus(in_f, out_f): | |
| output = open(out_f, 'w') | |
| wiki = WikiCorpus(in_f) | |
| i = 0 | |
| for text in wiki.get_texts(): | |
| output.write(bytes(' '.join(text), 'utf-8').decode('utf-8') + '\n') | |
| i = i + 1 | |
| if (i % 10000 == 0): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !git clone https://github.com/facebookresearch/fastText | |
| %cd fastText | |
| !mkdir build | |
| %cd build | |
| !cmake .. | |
| !make && make install |