Skip to content

Instantly share code, notes, and snippets.

View sarcasm-main.py
import en_textcat_sarcasm
nlp = en_textcat_sarcasm.load()
text = ['yea right, so funny', 'You forgot "Am I a joke to you" guy', "Pretty ballsey for Ted to mouth off to his bosses like that.", "I’m sure she is going to make an absolutely stellar cop, with no power trip agenda whatsoever", "Shut up, college boy!!"]
docs = list(nlp.pipe(text))
result = []
for doc in docs:
print(doc.text)
print(f"{doc.cats}\n")
View sarcasm-convert.py
"""Convert textcat annotation from JSONL to spaCy v3 .spacy format."""
import srsly
import typer
import warnings
from pathlib import Path
import spacy
from spacy.tokens import DocBin
View sarcasm-project.yml
title: "Demo Textcat (Text Classification)"
description: "A minimal demo textcat project for spaCy v3."
# Variables can be referenced across the project.yml using ${vars.var_name}
vars:
name: "textcat_sarcasm"
# Supported languages: all except ja, ko, th, vi, and zh, which would require
# custom tokenizer settings in config.cfg
lang: "en"
# Set your GPU ID, -1 is CPU
gpu_id: -1
View sarcasm-config.conf
[paths]
train = null
dev = null
vectors = null
init_tok2vec = null
[system]
seed = 0
gpu_allocator = null
View snownlp-print-sentences.py
from snownlp import SnowNLP
text = SnowNLP(u'这个产品很好用,这个产品不好用,这个产品是垃圾,这个也太贵了吧,超级垃圾,是个垃圾中的垃圾')
sent = text.sentences
for sen in sent:
s = SnowNLP(sen)
print(sen, s.sentiments)
View junit-complete-SimpleTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
View junit-first-SimpleTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class MyFirstJUnitJupiterTests {
@Test
void runningTest() {
assertEquals(2, 1 + 1);
}
}
View gcld3-test.py
import gcld3
detector = gcld3.NNetLanguageIdentifier(min_num_bytes=0, max_num_bytes=1000)
sample = "Welcome to Medium."
result = detector.FindLanguage(text=sample)
print(result.language, result.is_reliable, result.proportion, result.probability)
View extend-openapi-myapp.py
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
import os
app = FastAPI()
lable_lang_mapping = {"Plain JS": "JavaScript", "NodeJS": "JavaScript"}
@app.get("/hello")
async def hello():
View extend-openapi-add_examples.py
def add_examples(openapi_schema: dict, docs_dir):
path_key = 'paths'
code_key = 'x-codeSamples'
for folder in os.listdir(docs_dir):
base_path = os.path.join(docs_dir, folder)
files = [f for f in os.listdir(base_path) if os.path.isfile(os.path.join(base_path, f))]
for f in files:
parts = f.split('-')
if len(parts) >= 2: