RASMUS/Finnish-ASR-Canary-v2
02.2k
1# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15import argparse16import json17import os18 19"""20Create a dataset with five Lambada test examples for functional testing. Each line21contains a dictionary with a "text_before_last_word" and "last_word" keys.22"""23 24 25def create_sample_lambada(output_file: str, overwrite: bool = False):26 """Create JSON file with a few Lambada examples."""27 if os.path.isfile(output_file) and not overwrite:28 print(f"File {output_file} exists and overwrite flag is not set so exiting.")29 return30 31 texts = [32 {33 "text_before_last_word": "In my palm is a clear stone , and inside it is a small ivory statuette . A guardian angel .\n\n\" Figured if you re going to be out at night getting hit by cars , you might as well have some backup .\"\n\n I look at him , feeling stunned . Like this is some sort of sign . But as I stare at Harlin , his mouth curved in a confident grin , I don t care about",34 "last_word": "signs",35 },36 {37 "text_before_last_word": "Give me a minute to change and I ll meet you at the docks .\" She d forced those words through her teeth .\n\n\" No need to change . We won t be that long .\"\n\n Shane gripped her arm and started leading her to the dock .\n\n\" I can make it there on my own ,",38 "last_word": "Shane",39 },40 {41 "text_before_last_word": "\" Only one source I know of that would be likely to cough up enough money to finance a phony sleep research facility and pay people big bucks to solve crimes in their dreams ,\" Farrell concluded dryly .\n\n\" What can I say ?\" Ellis unfolded his arms and widened his hands . \" Your tax dollars at work .\"\n\n Before Farrell could respond , Leila s voice rose from inside the house .\n\n\" No insurance ?\" she wailed . \" What do you mean you don t have any",42 "last_word": "insurance",43 },44 {45 "text_before_last_word": "Helen s heart broke a little in the face of Miss Mabel s selfless courage . She thought that because she was old , her life was of less value than the others . For all Helen knew , Miss Mabel had a lot more years to live than she did . \" Not going to happen ,\" replied",46 "last_word": "Helen",47 },48 {49 "text_before_last_word": "Preston had been the last person to wear those chains , and I knew what I d see and feel if they were slipped onto my skin the Reaper s unending hatred of me . I d felt enough of that emotion already in the amphitheater . I didn t want to feel anymore .\n\n\" Don t put those on me ,\" I whispered . \" Please .\"\n\n Sergei looked at me , surprised by my low , raspy please , but he put down the",50 "last_word": "chains",51 },52 ]53 54 print(f"Writing {len(texts)} line(s) to {output_file}...")55 os.makedirs(os.path.dirname(os.path.abspath(output_file)), exist_ok=True)56 with open(output_file, mode="w", encoding="utf-8") as f:57 json.dump(texts, f)58 print("OK.")59 60 61if __name__ == "__main__":62 parser = argparse.ArgumentParser("Create a sample from Lambada test dataset.")63 parser.add_argument("--output_file", required=True, help="Output file name")64 parser.add_argument("--overwrite", action="store_true", help="Overwrite file if it exists")65 args = parser.parse_args()66 create_sample_lambada(args.output_file, args.overwrite)67 