docs/si/utils/index.html
[View code on Github](https://github.com/labmlai/annotated_deep_learning_paper_implementations/tree/master/labml_nn/utils/ init.py)
10importcopy1112fromtorch.utils.dataimportDataset,IterableDataset1314fromlabml\_helpers.moduleimportM,TypedModuleList
දීඇති මොඩියුලයක ක්ලෝන nn.ModuleList සමඟ සාදන්න
17defclone\_module\_list(module:M,n:int)-\>TypedModuleList[M]:
23returnTypedModuleList([copy.deepcopy(module)for\_inrange(n)])
එක්එක් එපෝච් පසු දත්ත කාරකය ප්රතිචක්රීකරණය කරන අනන්ත කාරකය
26defcycle\_dataloader(data\_loader):
34whileTrue:35forbatchindata\_loader:36yieldbatch
මෙය සිතියම් විලාසිතාවේ දත්ත කට්ටලයක් බවට IterableDataset පරිවර්තනය කරන අතර එමඟින් අපට දත්ත කට්ටලය මාරු කළ හැකිය.
මෙයක්රියාත්මක වන්නේ දත්ත සමුදාය ප්රමාණය කුඩා වන අතර මතකයේ රඳවා ගත හැකි විට පමණි.
39classMapStyleDataset(Dataset):
52def\_\_init\_\_(self,dataset:IterableDataset):
දත්තමතකය වෙත පූරණය කරන්න
54self.data=[dfordindataset]
දර්ශකයඅනුව නියැදියක් ලබා ගන්න
56def\_\_getitem\_\_(self,idx:int):
58returnself.data[idx]
කඅනුකාරකයක් සාදන්න
60def\_\_iter\_\_(self):
62returniter(self.data)
දත්තසමුදාය ප්රමාණය
64def\_\_len\_\_(self):
66returnlen(self.data)