This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a workaround for `examples/run_mlm.py` for pretraining models | |
with big text files line-by-line. | |
For the time being, `datasets` is facing some issues dealing with really | |
big text files, so we use a custom dataset until this is fixed. | |
August 3th 2021 | |
Author: Juan Manuel Pérez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [["dog", 1], ["cat", 2], ["bear", 3]]; | |
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array | |
const func2 = (obj, prop) => Object.assign(obj, prop); // assigns each object to an accumulator object | |
const obj3 = arr.map(func1).reduce(func2); // nesting | |
console.log(JSON.stringify(obj3, null, 2)); // Prints { "dog": 1, "cat": 2, "bear": 3 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [["dog", 1], ["cat", 2], ["bear", 3]]; | |
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array | |
const obj2 = arr.map(func1) | |
console.log(JSON.stringify(obj2, null, 2)); // Prints [ { "dog": 1 }, { "cat": 2 }, { "bear": 3 } ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reducer = (accum, curr) => accum + curr; | |
const result = [0, 1, 2, 3, 4].reduce(reducer); | |
console.log("result is", result); // result is 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const result = [0, 1, 2, 3, 4].reduce( (accum, curr) => accum + curr ) | |
console.log('result is', result) // result is 10 |