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 types import UnionType | |
from typing import Annotated, Any, ClassVar, TypeVar, Union, get_args, get_origin | |
from pydantic import Discriminator, Field, RootModel | |
T = TypeVar("T") | |
__all__ = ["UnionRootModel"] | |
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 logging import getLogger | |
from functools import wraps, lru_cache | |
from typing import Callable, Any | |
from datetime import datetime | |
log = getLogger(__name__) | |
def ttl_cache( |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
import re | |
import nltk | |
class Analyzer: | |
''' This analyzer applies the following transformation to an input text: | |
1. tokenize text into words | |
2. lowercase transform words | |
3. stem words | |
4. filter stopwords | |
5. replace all numbers with _num_ |
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
! pip3 install nltk --user | |
import os | |
import tensorflow as tf | |
import numpy as np | |
print(tf.__version__) | |
import nltk | |
nltk.download('movie_reviews') | |
nltk.download('punkt') |
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
# coding=utf-8 | |
# Copyright 2019 The Google Research Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
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
import zipfile | |
from io import TextIOWrapper | |
import numpy as np | |
import tensorflow as tf | |
import os | |
GLOVE_EMBEDDINGS = { | |
'glove.6B.50d' : ('http://nlp.stanford.edu/data/glove.6B.zip' , 50), | |
'glove.6B.100d' : ('http://nlp.stanford.edu/data/glove.6B.zip' , 100), | |
'glove.6B.200d' : ('http://nlp.stanford.edu/data/glove.6B.zip' , 200), |
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
import tensorflow as tf | |
class MultiHeadAttention(tf.keras.layers.Layer): | |
""" Mirrors the implementation from paper 'Attention Is All You Need' and | |
corresponding source code in | |
https://github.com/google-research/bert/blob/master/modeling.py. """ | |
def __init__(self, | |
size_per_head=16, | |
num_attention_heads=12, | |
dropout_rate=0, |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
def catplot(x, y, c, labels=None, title=None, n_categories=None, | |
s=10, alpha=0.65, cmap='rainbow', fig=None, ax=None, | |
border={'color': '0.7', 'linewidth': 1}, facecolor='white'): | |
if not fig: | |
fig, ax = plt.subplots(1, 1) | |
try: | |
N = int(n_categories) | |
except: |
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
Find: \\url{([^}]+)} | |
Replace: <$1> |
NewerOlder