This file contains 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
# Impor Library: | |
import pandas as pd # pandas as pd: Untuk manipulasi data dalam bentuk DataFrame. | |
import numpy as np # numpy as np: Untuk operasi numerik dan matriks. | |
from collections import defaultdict # collections.defaultdict: Untuk membuat kamus yang secara otomatis menginisialisasi nilai kunci baru dengan nilai default. | |
import spacy # spacy: Untuk pemrosesan bahasa, khususnya untuk tokenisasi. | |
import pickle # pickle: Untuk menyimpan dan mengambil objek Python, seperti DataFrame PMI. | |
from data_utils import * # data_utils: Ini adalah file terpisah yang berisi fungsi tambahan untuk pemrosesan data (tidak disertakan dalam kode ini). | |
# from nltk.corpus import stopwords # nltk.corpus.stopwords: Untuk menghilangkan kata-kata yang umum seperti "the", "a", "and" (dikomentari dalam kode). | |
# Fungsi Co-Occurence |
This file contains 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
# Impor librari yang diperlukan | |
import numpy as np # numpy: Digunakan untuk operasi numerik dan manipulasi matriks. | |
import torch.nn as nn # torch.nn: Digunakan untuk mendefinisikan arsitektur jaringan saraf. | |
import torch # torch: Digunakan untuk operasi tensor dan komputasi deep learning. | |
import pickle # pickle: Digunakan untuk menyimpan dan memuat objek Python. | |
from transformers import BertModel,BertTokenizer # transformers: Digunakan untuk mengimpor model BERT dan tokenizer. | |
# Kelas Tokenizer digunakan untuk mengubah teks menjadi urutan token numerik. | |
class Tokenizer(object): | |
def __init__(self, word2idx=None): |
This file contains 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
# Daftar librari yang dipakai | |
import os # os: Librari ini digunakan untuk berinteraksi dengan sistem operasi, seperti membuat direktori. | |
import math # math: Librari ini menyediakan fungsi matematika seperti sqrt yang digunakan untuk inisialisasi model. | |
import argparse # argparse: Librari ini digunakan untuk memproses argumen baris perintah, memungkinkan pengguna untuk menyesuaikan parameter model. | |
import random # random: Librari ini menyediakan fungsi untuk menghasilkan angka acak. | |
import numpy # numpy: Librari ini digunakan untuk manipulasi array multidimensi. | |
import torch # torch: Librari PyTorch, dasar untuk membangun model deep learning. | |
import torch.nn as nn # torch.nn: Submodul PyTorch yang menyediakan kelas dan fungsi untuk membangun arsitektur jaringan saraf. | |
from sklearn import metrics # sklearn: Librari scikit-learn, yang menyediakan fungsi untuk metrik evaluasi seperti f1_score. | |
from data_utils import DDIDatesetReader # data_utils: Modul yang didefinisikan sendiri, berisi kelas DDIDatesetReader yan |
This file contains 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
# RegCN | |
import math # Untuk fungsi matematika dasar | |
import torch # Librari utama untuk komputasi tensor dalam PyTorch | |
import torch.nn as nn # Modul untuk membangun jaringan saraf | |
import torch.nn.functional as F # Fungsi aktivasi dan operasi umum dalam jaringan saraf | |
from transformers import BertModel # Model BERT dari pustaka Transformers, untuk embedding teks | |
# Modul DynamicLSTM yang didefinisikan secara terpisah, mungkin untuk menangani panjang urutan yang variabel | |
from layers.dynamic_rnn import DynamicLSTM |
This file contains 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
# Dependency Graph | |
import numpy as np # Mengimpor library NumPy dan menyingkatnya sebagai np untuk penggunaan selanjutnya. NumPy digunakan untuk manipulasi array dan matriks | |
import spacy # Mengimpor library spaCy, yang merupakan library Pemrosesan Bahasa Alami (NLP) yang kuat untuk pengolahan teks | |
import pickle # Mengimpor library pickle, yang digunakan untuk menyimpan objek Python dalam file biner, yang memungkinkan pemuatan kembali objek tersebut nanti | |
# Memuat model bahasa spaCy yang dilatih sebelumnya untuk bahasa Inggris | |
# Model ini akan digunakan untuk menganalisis sintaksis teks. | |
nlp = spacy.load('en_core_web_sm') |
This file contains 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
var m,_,afState={arrLen:{},form:{}},{stringify,parse}=JSON,autoForm=opts=>({view:()=>{var withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),normal=name=>name.replace(/\d/g,'$'),fileData=(key,val)=>{var form=new FormData();form.append(key,val);return form},dateValue=(timestamp,hour)=>{var date=new Date(timestamp),zeros=num=>num<10?'0'+num:''+num,dateStamp=[date.getFullYear(),zeros(date.getMonth()+1),zeros(date.getDate())].join('-'),hourStamp=['T',zeros(date.getHours()),':',zeros(date.getMinutes())].join('');return!hour?dateStamp:dateStamp+hourStamp},linearize=obj=>{var recurse=doc=>withAs(doc[_.keys(doc)[0]],value=>typeof(value)==='object'?_.map(value,(val,key)=>recurse({[_.keys(doc)[0]+'.'+key]:val})):doc);return _.fromPairs(_.flattenDeep(recurse({doc:obj})).map(i=>[_.keys(i)[0].substr(4),_.values(i)[0]]))}afState.form[opts.id]=opts.doc?_.assign(afState.form[opts.id],linearize(opts.doc)):afState.form[opts.id];var attr={form: |
This file contains 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
var m,_,mgState={},comps={},state={},withAs=(opts,cb)=>cb(opts),ifit=(opts,cb)=>Boolean(opts)&&cb(opts),ands=array=>array.reduce((a,b)=>a&&b,true),makeArray=n=>[...Array(n).keys()],makeIconLabel=(icon,label)=>[icon&&m('span.icon',m('i.fas.fa-'+icon)),m('span',label)],poster=(url,body,cb)=>fetch(url,{headers:{'Content-Type':'application/json'},method:'post',body:JSON.stringify(body)}).then(res=>res.json()).then(cb),mitGen=opts=>({view:()=>m('div',{class:'has-background-light'},opts.theme&&m('link',{rel:'stylesheet',href:`https://unpkg.com/bulmaswatch/${opts.theme }/bulmaswatch.min.css`}),m('nav.navbar.is-primary.is-fixed-top',m('.navbar-brand',m('a.navbar-item',{onclick:()=>[_.assign(mgState,{comp:undefined}),m.redraw()]},opts.brand.full||opts.brand.name),m('.navbar-burger',{role:'button',class:mgState.burgerMenu&&'is-active',onclick:()=>mgState.burgerMenu=!mgState.burgerMenu},_.range(3).map(i=>m('span',{'aria-hidden':true})))),m('.navbar-menu',{class:mgState.burgerMenu&&'is-active'},m('.navbar-start',_.map(op |
This file contains 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
var atState={},ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),timestamp=str=> +(new Date(str)),atModify=(rows,opts)=>rows .filter(i=>withAs({start:_.get(atState,[opts.id,'start_range']),end:_.get(atState,[opts.id,'end_range']),func:eval(_.get(atState,[opts.id,'rangeFunc']))},({start,end,func})=>ands([start,end,timestamp(start)<timestamp(end)])?func(i,timestamp(start),timestamp(end)):i)).filter(i=>ands(_.map(_.get(atState,[opts.id,'filters']),(val,key)=>opts.filters[key].find(j=>j.label===val)).map(j=>j.func(i.data)))).filter(i=>_.values(i.row).map(_.lowerCase).join('').includes(_.get(atState,[opts.id,'search'])||'')).sort((a,b)=>_.get(atState,[opts.id,'sortBy'])&&_[_.get(atState,[opts.id,'sortWay'])?'gt':'lt'](a.row[_.get(atState,[opts.id,'sortBy'])],b.row[_.get(atState,[opts.id,'sortBy'])])?-1:1).slice((_.get(atState,[opts.id,'activeStep'])||0)*(_.get(atState,[opts.id,'pagination'])||0),((_.get(atState,[opts.id,'activeSt |
This file contains 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
var m,_,afState={arrLen:{},form:{}},{stringify,parse}=JSON,autoForm=opts=>({view:()=>{var withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),normal=name=>name.replace(/\d/g,'$'),fileData=(key,val)=>{var form=new FormData();form.append(key,val);return form},dateValue=(timestamp,hour)=>{var date=new Date(timestamp),zeros=num=>num<10?'0'+num:''+num,dateStamp=[date.getFullYear(),zeros(date.getMonth()+1),zeros(date.getDate())].join('-'),hourStamp=['T',zeros(date.getHours()),':',zeros(date.getMinutes())].join('');return!hour?dateStamp:dateStamp+hourStamp},linearize=obj=>{var recurse=doc=>withAs(doc[_.keys(doc)[0]],value=>typeof(value)==='object'?_.map(value,(val,key)=>recurse({[_.keys(doc)[0]+'.'+key]:val})):doc);return _.fromPairs(_.flattenDeep(recurse({doc:obj})).map(i=>[_.keys(i)[0].substr(4),_.values(i)[0]]))}afState.form[opts.id]=opts.doc?_.assign(afState.form[opts.id],linearize(opts.doc)):afState.form[opts.id];var attr={form: |
This file contains 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
cityMap = { | |
a: {b: 20, d: 80, g: 90}, | |
b: {f: 10}, | |
c: {f: 50, h: 20, d: 10}, | |
d: {g: 20, c: 10}, | |
e: {b: 50, g: 30}, | |
f: {c: 10, d: 40}, | |
g: {a: 20}, | |
h: {h: 0} | |
} |
NewerOlder