Skip to content

Instantly share code, notes, and snippets.

@lhr0909
lhr0909 / convert.py
Created June 3, 2024 02:10
Convert RescueTime CSV into ActivityWatch bucket JSON
import csv
import json
import datetime
events = []
# Open the CSV
with open("portable_user_history-2024-06-02-csv.csv", "r") as f:
reader = csv.DictReader(
f,
@lhr0909
lhr0909 / nlu_results
Created August 26, 2022 04:44
DIET Classifier PyTorch Snippets
📄 Document: 390ade4aa6f98236224082851331c670
╭───────────┬──────────────────────────────────────────────────────────────────╮
│ Attribute │ Value │
├───────────┼──────────────────────────────────────────────────────────────────┤
│ text │ Naw man │
│ embedding │ ▄▄▄ │
╰───────────┴──────────────────────────────────────────────────────────────────╯
└── 🔶 Matches
├── 📄 Document: 626c8c7ed40279b4152aae627223e253
│ ╭───────────┬──────────────────────────────────────────────────────────────────╮
@lhr0909
lhr0909 / infer.py
Created August 26, 2022 04:43
DIET Classifier PyTorch Snippets
from jina import Flow
from docarray import DocumentArray, Document
from executor import DIETClassifierExecutor
f = Flow().add(
uses='jinahub+docker://ConveRTFeaturizer/latest'
).add(
uses=DIETClassifierExecutor, uses_with={ 'model_path': './lightning_logs/version_4/checkpoints/epoch=999-step=1000.ckpt' }
)
@lhr0909
lhr0909 / diet_classifier_executor.py
Created August 26, 2022 04:24
DIET Classifier PyTorch Snippets
from typing import Any, Dict, List
import yaml
from pathlib import Path
from jina import Executor, requests
from docarray import DocumentArray, Document
from docarray.score import NamedScore
import torch
import torch.nn.functional as F
from diet_classifier.config import DIETClassifierConfig
@lhr0909
lhr0909 / nlu.yml
Created August 26, 2022 04:10
DIET Classifier PyTorch Snippets
nlu:
- intent: greet
examples:
- Hello
- Hi
- Hey
- intent: affirm
examples:
- "Yes"
- "Yes, that's right"
@lhr0909
lhr0909 / data.py
Created August 26, 2022 04:04
DIET Classifier PyTorch Snippets
from typing import Dict, Any, List
from pathlib import Path
import yaml
import torch
import pytorch_lightning as pl
from torch.utils.data import DataLoader
from jina import Flow
from docarray import DocumentArray, Document
@lhr0909
lhr0909 / convert_featurizer.py
Created August 26, 2022 03:59
DIET Classifier PyTorch Snippets
from conversational_sentence_encoder.vectorizers import SentenceEncoder
from jina import Executor, requests
from docarray import DocumentArray
class ConveRTFeaturizer(Executor):
def __init__(self, multiple_contexts=False, **kwargs):
super(ConveRTFeaturizer, self).__init__(**kwargs)
self.sentence_encoder = SentenceEncoder(multiple_contexts=multiple_contexts)
@requests
@lhr0909
lhr0909 / classifier.py
Created August 26, 2022 03:34
DIET Classifier PyTorch Snippets
import torch
from torch import optim, nn, Tensor
import torch.nn.functional as F
import pytorch_lightning as pl
from .config import DIETClassifierConfig
from .models import IntentClassifier
class DIETClassifier(pl.LightningModule):
def __init__(self, config: DIETClassifierConfig):
@lhr0909
lhr0909 / models.py
Last active August 26, 2022 03:33
DIET Classifier PyTorch Snippets
import torch
from torch import nn, Tensor
from .config import DIETClassifierConfig
class IntentClassifier(nn.Module):
def __init__(self, config: DIETClassifierConfig):
super().__init__()
# Rasa's embedding layer is actually a "dense embedding layer" which is just a Keras dense layer
# equivalent to a PyTorch Linear layer.

Keybase proof

I hereby claim:

  • I am lhr0909 on github.
  • I am lhr0909 (https://keybase.io/lhr0909) on keybase.
  • I have a public key ASBuOVwpHfFIg-c6qEl2uyn_ANt93FTFtv_XTVkSJ2bkeAo

To claim this, I am signing this object: