Skip to content

Commit

Permalink
add first test
Browse files Browse the repository at this point in the history
Signed-off-by: andrusenkoau <andrusenkoau@gmail.com>
  • Loading branch information
andrusenkoau committed Jan 19, 2024
1 parent ec53a70 commit d639478
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ContextGraphCTC:
A ContextGraph contains some words / phrases that we expect to boost their recognition accuracy.
"""

def __init__(self, blank_id=1024):
def __init__(self, blank_id: int = 1024):
"""
Initialize the ContextGraphCTC based on given blank_id.
Expand All @@ -79,7 +79,7 @@ def __init__(self, blank_id=1024):
self.root = ContextState(index=self.num_nodes, is_end=False)
self.blank_token = blank_id

def build(self, word_items: List[Union[str, List[List[int]]]]):
def build(self, word_items: List[Union[str, List[List[Union[str, int]]]]]):
"""
Build the context graph based on given word_items.
Expand Down
29 changes: 29 additions & 0 deletions tests/collections/asr/test_asr_context_biasing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os
from functools import lru_cache
import pytest
import torch
from nemo.collections.asr.parts.context_biasing.context_graph_ctc import ContextGraphCTC


class TestContextGraphCTC:
@pytest.mark.unit
def test_graph_building(self):
context_biasing_list = [["gpu", [['▁g', 'p', 'u'], ['▁g', '▁p', '▁u']]]]
context_graph = ContextGraphCTC(blank_id=1024)
context_graph.build(context_biasing_list)
assert context_graph.num_nodes == 8

0 comments on commit d639478

Please sign in to comment.