本文簡要介紹python語言中 torchdata.datapipes.iter.ParagraphAggregator
的用法。
用法:
class torchdata.datapipes.iter.ParagraphAggregator(source_datapipe: IterDataPipe[Tuple[str, T_co]], joiner: Callable = <function _default_line_join>)
source_datapipe-帶有文件名和行元組的 DataPipe
joiner-將行列表連接在一起的函數
將同一文件中的文本行聚合到單個段落中(函數名稱:
lines_to_paragraphs
)。具體來說,它接受由文件名和行的元組組成的DataPipe。對於每個元組,它檢查文件名是否與前一個元組的文件名匹配。如果是,它將當前行與現有段落連接起來。如果文件名不匹配,則生成現有段落並開始新段落。示例
>>> from torchdata.datapipes.iter import IterableWrapper >>> source_dp = IterableWrapper( >>> [("file1", "Line1"), ("file1", "Line2"), ("file2", "Line2,1"), ("file2", "Line2,2"), ("file2", "Line2,3")] >>> ) >>> para_agg_dp = source_dp.lines_to_paragraphs(joiner=lambda ls: " ".join(ls)) >>> list(para_agg_dp) [('file1', 'Line1 Line2'), ('file2', 'Line2,1 Line2,2 Line2,3')]
參數:
相關用法
- Python PyTorch ParallelReadConcat用法及代碼示例
- Python PyTorch ParameterList用法及代碼示例
- Python PyTorch ParameterDict用法及代碼示例
- Python PyTorch ParquetDataFrameLoader用法及代碼示例
- Python PyTorch Pareto用法及代碼示例
- Python PyTorch PackageImporter.id用法及代碼示例
- Python PyTorch PackageExporter.register_extern_hook用法及代碼示例
- Python PyTorch PairwiseDistance用法及代碼示例
- Python PyTorch PackageExporter.register_intern_hook用法及代碼示例
- Python PyTorch PackageExporter.close用法及代碼示例
- Python PyTorch PackageExporter.register_mock_hook用法及代碼示例
- Python PyTorch Proxy用法及代碼示例
- Python PyTorch PoissonNLLLoss用法及代碼示例
- Python PyTorch PixelShuffle用法及代碼示例
- Python PyTorch Pipe用法及代碼示例
- Python PyTorch PooledEmbeddingsAllToAll用法及代碼示例
- Python PyTorch Poisson用法及代碼示例
- Python PyTorch Perceptron用法及代碼示例
- Python PyTorch PixelUnshuffle用法及代碼示例
- Python PyTorch PitchShift用法及代碼示例
- Python PyTorch PooledEmbeddingsReduceScatter用法及代碼示例
- Python PyTorch PReLU用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torchdata.datapipes.iter.ParagraphAggregator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。