Skip to content

Commit

Permalink
Merge pull request #8 from neulab/neubig/fix_continuous_integration
Browse files Browse the repository at this point in the history
Fixed continuous integration
  • Loading branch information
rohanmodi2810 authored Feb 19, 2024
2 parents 87c909a + da85e10 commit 17c7ae0
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 52 deletions.
29 changes: 3 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: Continuous Integration
on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
push:
branches:
- main
Expand All @@ -18,7 +19,7 @@ jobs:
- name: Install ruff
run: pip install ruff
- name: Run ruff
run: ruff --check .
run: ruff check .
python-mypy:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,14 +32,6 @@ jobs:
uses: pre-commit/action@v3.0.0
with:
extra_args: mypy --all-files
lint-requirements-txt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: lint
uses: pre-commit/action@v3.0.0
with:
extra_args: requirements-txt-fixer --all-files
lint-markdown:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -75,19 +68,3 @@ jobs:
uses: pre-commit/action@v3.0.0
with:
extra_args: shellcheck --all-files
lint-trailing-whitespace:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: lint
uses: pre-commit/action@v3.0.0
with:
extra_args: trailing-whitespace --all-files
lint-eof-newline:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: lint
uses: pre-commit/action@v3.0.0
with:
extra_args: end-of-file-fixer --all-files
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Release workflow

on:
on: # yamllint disable-line rule:truthy
push:
tags:
- "v[0123456789].*"

jobs:
release:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ __pycache__
build
llments.egg-info
.vscode
.pytest_cache
.pytest_cache
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
rev: v0.2.1
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.6.1'
rev: v1.8.0
hooks:
- id: mypy
- id: mypy
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.10.0
rev: v0.12.1
hooks:
- id: markdownlint-cli2
- repo: https://github.com/adrienverge/yamllint
rev: v1.33.0
rev: v1.34.0
hooks:
- id: yamllint
- repo: https://github.com/koalaman/shellcheck-precommit
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

## Development Information

To start developing, install the development dependencies and pre-commit hooks:

```bash
pip install .
pip install ".[dev]"
pre-commit install
```

There are several [pre-commit hooks](https://pre-commit.com/) that will run on every
commit to perform formatting, typing, and linting.

* `ruff` - Runs formatting, import sorting, and linting.
* `mypy` - Runs type checking.
* `markdownlint` - Runs markdown linting.
* `yamllint` - Runs YAML linting.
4 changes: 1 addition & 3 deletions llments/distance/distance.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

import abc

from llments.lm.lm import LanguageModel


class Distance:

@abc.abstractclassmethod
@abc.abstractmethod
def distance(self, lm1: LanguageModel, lm2: LanguageModel) -> float:
"""Returns a distance between two language models."""
...
1 change: 0 additions & 1 deletion llments/distance/norm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from llments.lm.lm import LanguageModel


Expand Down
5 changes: 2 additions & 3 deletions llments/eval/eval.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import abc
import dataclasses


class PairwiseEvaluator:
"""A class that defines an evaluation function, assessing a hypothesized string."""

@abc.abstractclassmethod
@abc.abstractmethod
def evaluate(self, hyp: str, ref: str) -> float:
"""Returns an evaluation score between 0 and 1 for two strings.
Expand All @@ -25,7 +24,7 @@ class EvaluatorMetadata:
class GeneralEvaluator:
"""A class that defines an evaluation function, assessing a hypothesized string."""

@abc.abstractclassmethod
@abc.abstractmethod
def evaluate(self, hyp: str, ref: EvaluatorMetadata) -> float:
"""Returns an evaluation score between 0 and 1 for two strings.
Expand Down
9 changes: 5 additions & 4 deletions llments/lm/empirical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any
from llments.lm.lm import LanguageModel
import random
import json
Expand All @@ -10,10 +11,10 @@ def __init__(self, data: list[str], probs: list[float] | None = None):
probs = [1 / len(data)] * len(data)
self.data = pd.DataFrame({"text": data, "prob": probs})

def sample(self, condition: str | None):
def generate(self, condition: str | None, **kwargs: Any) -> str:
"""Sample from the language model, possibly conditioned on a prefix."""
if condition is None:
return random.choice(self.data["text"], p=self.data["probs"])
return random.choices(self.data["text"], weights=self.data["probs"])[0]
else:
# Filter to only those that start with the condition
filtered_df = self.data[self.data["text"].str.startswith(condition)]
Expand All @@ -24,9 +25,9 @@ def sample(self, condition: str | None):
)
# Normalize the probabilities
filtered_df["prob"] = filtered_df["prob"] / filtered_df["prob"].sum()
return random.choice(filtered_df["text"], p=filtered_df["probs"])
return random.choices(filtered_df["text"], weights=filtered_df["probs"])[0]

def fit(self, target: LanguageModel):
def fit(self, target: LanguageModel, task_description: str | None = None):
raise ValueError(
"Cannot fit an empirical distribution to another distribution."
)
Expand Down
4 changes: 2 additions & 2 deletions llments/lm/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class LanguageModel:
@abc.abstractclassmethod
@abc.abstractmethod
def generate(
self,
condition: str | None,
Expand All @@ -11,7 +11,7 @@ def generate(
"""Generate from the language model, possibly conditioned on a prefix."""
...

@abc.abstractclassmethod
@abc.abstractmethod
def fit(
self, target: "LanguageModel", task_description: str | None = None
) -> "LanguageModel":
Expand Down
2 changes: 0 additions & 2 deletions llments/lm/lm_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


from llments.lm.lm import LanguageModel


Expand Down
1 change: 0 additions & 1 deletion llments/lm/lm_loader_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def test_load_from_spec_file():
"""Test that load_from_specification_file() loads a language model."""
raise NotImplementedError

0 comments on commit 17c7ae0

Please sign in to comment.