Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: compute_score sig #34

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Implement ngram counts with a better way (#33)
- Rust `compute_score` function signature changed to use references (#34)

## [0.1.1] - 2024-04-26
### Changed
Expand Down
6 changes: 3 additions & 3 deletions src/bleu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct BleuScore {
/// compute the BLEU score with `Tokenizer13a` as default tokenizer.
/// The implementation is based on [huggingface/nmt](https://github.com/huggingface/evaluate/blob/main/metrics/bleu/bleu.py)
pub fn compute_score(
references: Vec<Vec<String>>,
predictions: Vec<String>,
references: &[Vec<String>],
predictions: &[String],
max_order: usize,
smooth: bool,
) -> BleuScore {
Expand Down Expand Up @@ -125,7 +125,7 @@ mod test {
let predictions: Vec<String> = vec!["Yellow, World!".to_string()];
let max_order: usize = 4;
let smooth: bool = true;
let res = compute_score(references, predictions, max_order, smooth);
let res = compute_score(&references, &predictions, max_order, smooth);
// (0.668740304976422, [0.8, 0.75, 0.6666666666666666, 0.5], 1.0, 1.0, 4, 4)
println!("result: {:?}", res);
assert!((res.bleu - 0.668740304976422).abs() < 1e-10);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
max_order: usize,
smooth: bool,
) -> PyResult<PyObject> {
let bleu = compute_score(references, predictions, max_order, smooth);
let bleu = compute_score(&references, &predictions, max_order, smooth);

Check warning on line 71 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L71

Added line #L71 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit tests for the modified compute function.

Would you like me to help by writing some unit tests or should I open a GitHub issue to track this task?

Python::with_gil(|py| {
let bleu_dict = [
("bleu", bleu.bleu.to_object(py)),
Expand Down
Loading