def test_from_json(tmpdir): json_path = json_data(tmpdir) dm = SummarizationData.from_files( backbone=TEST_BACKBONE, train_file=json_path, input="input", target="target", filetype="json", batch_size=1 ) batch = next(iter(dm.train_dataloader())) assert "labels" in batch assert "input_ids" in batch
def test_from_csv(tmpdir): if os.name == "nt": # TODO: huggingface stuff timing out on windows return True csv_path = csv_data(tmpdir) dm = SummarizationData.from_files(backbone=TEST_BACKBONE, train_file=csv_path, input="input", target="target", batch_size=1) batch = next(iter(dm.train_dataloader())) assert "labels" in batch assert "input_ids" in batch
def test_from_files(tmpdir): csv_path = csv_data(tmpdir) dm = SummarizationData.from_files( backbone=TEST_BACKBONE, train_file=csv_path, val_file=csv_path, test_file=csv_path, input="input", target="target", batch_size=1 ) batch = next(iter(dm.val_dataloader())) assert "labels" in batch assert "input_ids" in batch batch = next(iter(dm.test_dataloader())) assert "labels" in batch assert "input_ids" in batch
# See the License for the specific language governing permissions and # limitations under the License. import torch import flash from flash import download_data, Trainer from flash.text import SummarizationData, SummarizationTask # 1. Download the data download_data("https://pl-flash-data.s3.amazonaws.com/xsum.zip", "data/") # 2. Load the data datamodule = SummarizationData.from_files( train_file="data/xsum/train.csv", val_file="data/xsum/valid.csv", test_file="data/xsum/test.csv", input="input", target="target" ) # 3. Build the model model = SummarizationTask() # 4. Create the trainer. Run once on data trainer = flash.Trainer(gpus=int(torch.cuda.is_available()), fast_dev_run=True) # 5. Fine-tune the model trainer.finetune(model, datamodule=datamodule) # 6. Save it! trainer.save_checkpoint("summarization_model_xsum.pt")
""" Camilla bought a box of mangoes with a Brixton £10 note, introduced last year to try to keep the money of local people within the community.The couple were surrounded by shoppers as they walked along Electric Avenue. They came to Brixton to see work which has started to revitalise the borough. It was Charles' first visit to the area since 1996, when he was accompanied by the former South African president Nelson Mandela.Greengrocer Derek Chong, who has run a stall on Electric Avenue for 20 years, said Camilla had been ""nice and pleasant"" when she purchased the fruit. ""She asked me what was nice, what would I recommend, and I said we've got some nice mangoes. She asked me were they ripe and I said yes - they're from the Dominican Republic."" Mr Chong is one of 170 local retailers who accept the Brixton Pound. Customers exchange traditional pound coins for Brixton Pounds and then spend them at the market or in participating shops. During the visit, Prince Charles spent time talking to youth worker Marcus West, who works with children nearby on an estate off Coldharbour Lane. Mr West said: ""He's on the level, really down-to-earth. They were very cheery. The prince is a lovely man."" He added: ""I told him I was working with young kids and he said, 'Keep up all the good work.'"" Prince Charles also visited the Railway Hotel, at the invitation of his charity The Prince's Regeneration Trust. The trust hopes to restore and refurbish the building, where once Jimi Hendrix and The Clash played, as a new community and business centre." """ ]) print(predictions) # 2b. Or generate summaries from a sheet file! datamodule = SummarizationData.from_files( predict_file="data/xsum/predict.csv", input="input", ) predictions = Trainer().predict(model, datamodule=datamodule) print(predictions)