Skip to content

Instantly share code, notes, and snippets.

View sebastianschramm's full-sized avatar

Sebastian M. Schramm sebastianschramm

View GitHub Profile
@sebastianschramm
sebastianschramm / ner_with_uniner-7b-definition-gptq-4bit.ipynb
Created August 27, 2023 11:21
ner_with_uniner-7b-definition-gptq-4bit.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sebastianschramm
sebastianschramm / ner_with_uniner-7b-type-gptq-4bit.ipynb
Created August 27, 2023 11:15
ner_with_uniner-7b-type-gptq-4bit.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sebastianschramm
sebastianschramm / ner_with_uniner-7b-all-gptq-4bit.ipynb
Created August 26, 2023 11:29
NER_with_UniNER-7B-all-GPTQ-4bit.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sebastianschramm
sebastianschramm / union_operator_for_typing.py
Created August 31, 2022 16:45
How to use the union operator instead of Union for typing
from typing import Union
def is_valid_type(object):
return isinstance(object, Union[str, None])
def is_valid_type_new(object):
return isinstance(object, str | None)
@sebastianschramm
sebastianschramm / pandas_testing.py
Created August 30, 2022 16:34
How to use pandas testing assert_frame_equal
import pandas as pd
from pandas.testing import assert_frame_equal
df_one = pd.DataFrame(
{"city": ["Tokyo", "Delhi"], "population": [13_515_271, 16_753_235]}
)
df_two = df_one[["population", "city"]].copy(deep=True)
assert_frame_equal(left=df_one, right=df_two)
@sebastianschramm
sebastianschramm / zip_strict.py
Created August 29, 2022 13:11
How to use zip with strict since py3.10
names = ['a', 'b', 'c']
values = [10, 54, 2]
values_too_long = values + [10]
"""
>>> {k: v for k, v in zip(names, values_too_long, strict=True)}
ValueError: zip() argument 2 is longer than argument 1
>>> {k: v for k, v in zip(names, values_too_long, strict=False)}
{'a': 10, 'b': 54, 'c': 2}
@sebastianschramm
sebastianschramm / pandarallel_apply.py
Created August 26, 2022 14:53
An easy way to parallelize pandas.apply processing
import pandas as pd
from pandarallel import pandarallel
from sklearn.datasets import fetch_20newsgroups
def preprocess_text(row: pd.Series) -> float:
return [word.lower() for word in row.text.split()]
def get_data() -> pd.DataFrame:
@sebastianschramm
sebastianschramm / pytest_parametrize_fixture.py
Created August 25, 2022 16:40
How to parametrize fixtures in pytest
import json
import pytest
@pytest.fixture
def min_dict():
return {"name": "foo"}
@sebastianschramm
sebastianschramm / read_envs_pydantic_basesettings.py
Created August 24, 2022 16:10
How to read ENVs with pydantic.BaseSettings
from pydantic import BaseSettings, Field, SecretStr
class Credentials(BaseSettings):
password: SecretStr = Field(..., env="DB_PASSWORD")
"""
>>> Credentials()
pydantic.error_wrappers.ValidationError: 1 validation error for Credentials
@sebastianschramm
sebastianschramm / pydantic_secretstr.py
Created August 23, 2022 14:46
Protect your secrets from being accidentally exposed by logging
from pydantic import SecretStr
# NOTE: it is usually not a good idea to hard-code your passwords,
# this is just for illustration purposes
my_password = SecretStr("adminAdmin123")
"""
>>> str(my_password)
'**********'
>>> print(my_password)