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
#from tensorflow.keras.callbacks import EarlyStopping | |
early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True) | |
model.fit(train_dataset.shuffle(1000).batch(16), | |
epochs=2, | |
batch_size=16, | |
validation_data=val_dataset.shuffle(1000).batch(16), | |
callbacks=[early_stopping]) |
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
model = TFDistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased', num_labels=5) | |
optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5, epsilon=1e-08) | |
model.compile(optimizer=optimizer, loss=model.hf_compute_loss, metrics=['accuracy']) |
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
train_dataset = tf.data.Dataset.from_tensor_slices(( | |
dict(train_encodings), | |
train_labels | |
)) | |
val_dataset = tf.data.Dataset.from_tensor_slices(( | |
dict(val_encodings), | |
val_labels | |
)) |
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
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased') | |
train_encodings = tokenizer(train_texts, truncation=True, padding=True) | |
val_encodings = tokenizer(val_texts, truncation=True, padding=True) |
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
from sklearn.model_selection import train_test_split | |
# Split Train and Validation data | |
train_texts, val_texts, train_labels, val_labels = train_test_split(data_texts, data_labels, test_size=0.2, random_state=0, shuffle=True) | |
# Keep some data for inference (testing) | |
train_texts, test_texts, train_labels, test_labels = train_test_split(train_texts, train_labels, test_size=0.01, random_state=0, shuffle=True) |
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
url = 'https://github.com/kiddojazz/Multitext-Classification/blob/master/bbc_data.csv?raw=true' | |
#df = pd.read_csv(url,index_col=0) | |
df = pd.read_csv(url) | |
print(df.head(5)) |
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
from transformers import DistilBertTokenizer | |
from transformers import TFDistilBertForSequenceClassification | |
import tensorflow as tf | |
import pandas as pd |
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
select * from( | |
select customer_id, state_, profit_total, | |
rank() over(partition by state_ order by profit_total desc) as Rank_row | |
from customer_order_window) as rank_info | |
where rank_row = 1; |
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
select customer_id, state_, profit_total, | |
first_value(profit_total) over(partition by state_ order by profit_total desc) as first_row | |
from customer_order_window; |
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
select customer_id, state_, profit_total, | |
LEAD(profit_total) over(partition by state_ order by profit_total desc) as Lead_row | |
from customer_order_window; |