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 dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| import google.generativeai as genai | |
| from data_model import ( | |
| TouristLocation, | |
| ClimateType, | |
| ActivityType, |
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
| # First install https://github.com/yakupadakli/python-unsplash | |
| # Unsplash API https://unsplash.com/documentation | |
| import json | |
| import os | |
| from unsplash.api import Api | |
| from unsplash.auth import Auth | |
| with open('tokens.json', 'r') as f: | |
| data = json.load(f) |
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
| def get_model(n_class=5): | |
| inp = Input(shape=(187, 1)) | |
| x = Convolution1D(64, kernel_size=5, activation=activations.relu, padding="valid")( | |
| inp | |
| ) | |
| x = MaxPool1D(pool_size=4)(x) | |
| x = Convolution1D(64, kernel_size=3, activation=activations.relu, padding="valid")( | |
| x | |
| ) | |
| x = MaxPool1D(pool_size=4)(x) |
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 numpy as np | |
| def kl_loss(y_true, y_pred): | |
| return np.sum(y_true * np.log(y_true / y_pred)) | |
| y_true = np.array([0.1, 0.5, 0.2, 0.15, 0.05]) | |
| y_pr_1 = np.array([0.15, 0.4, 0.2, 0.2, 0.05]) | |
| y_pr_2 = np.array([0.5, 0.1, 0.1, 0.2, 0.1]) |
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
| for i, step_size in enumerate(step_sizes): | |
| X_used = X[used_samples, ...] | |
| Y_used = Y[used_samples, ...] | |
| X_unused = X[unused_samples, ...] | |
| Y_unused = Y[unused_samples, ...] | |
| model = get_model() |
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
| for i, step_size in enumerate(step_sizes): | |
| X_used = X[used_samples, ...] | |
| Y_used = Y[used_samples, ...] | |
| X_unused = X[unused_samples, ...] | |
| Y_unused = Y[unused_samples, ...] | |
| model = get_model() |
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
| X_used = X[used_samples, ...] | |
| Y_used = Y[used_samples, ...] | |
| X_unused = X[unused_samples, ...] | |
| Y_unused = Y[unused_samples, ...] | |
| model = get_model() | |
| model.fit(X_used, Y_used, epochs=45, verbose=1, batch_size=32) |
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
| step_sizes = [128]*20 # Succesive batch sizes | |
| unused_samples = list(range(X.shape[0])) # Indexes of samples that were not used for training yet | |
| step = np.random.choice(unused_samples, size=512).tolist() # First batch | |
| used_samples = step # Indexes of samples that were used for training | |
| unused_samples = list(set(unused_samples) - set(step)) |
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
| def get_graph_embedding_model(n_nodes): | |
| in_1 = Input((1,)) | |
| in_2 = Input((1,)) | |
| emb = Embedding(n_nodes, 100, name="node1") | |
| x1 = emb(in_1) | |
| x2 = emb(in_2) | |
| x1 = Flatten()(x1) | |
| x1 = Dropout(0.1)(x1) | |
| x2 = Flatten()(x2) | |
| x2 = Dropout(0.1)(x2) |
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
| def get_features_only_model(n_features, n_classes): | |
| in_ = Input((n_features,)) | |
| x = Dense(10, activation="relu", kernel_regularizer=l1(0.001))(in_) | |
| x = Dropout(0.5)(x) | |
| x = Dense(n_classes, activation="softmax")(x) | |
| model = Model(in_, x) | |
| model.compile(loss="sparse_categorical_crossentropy", metrics=['acc'], optimizer="adam") |
NewerOlder