/ mlflow / utils / name_utils.py
name_utils.py
  1  import random
  2  import uuid
  3  
  4  _EXPERIMENT_ID_FIXED_WIDTH = 18
  5  
  6  
  7  def _generate_unique_integer_id():
  8      """Utility function for generating a random fixed-length integer
  9  
 10      Args:
 11          id_length: The target length of the string representation of the integer without
 12              leading zeros
 13  
 14      Returns:
 15          a fixed-width integer
 16      """
 17  
 18      random_int = uuid.uuid4().int
 19      # Cast to string to get a fixed length
 20      random_str = str(random_int)[-_EXPERIMENT_ID_FIXED_WIDTH:]
 21      # append a random int as string to the end of the generated string for as many
 22      # leading zeros exist in the generated string in order to preserve the total length
 23      # once cast back to int
 24      for s in random_str:
 25          if s == "0":
 26              random_str = random_str + str(random.randint(0, 9))
 27          else:
 28              break
 29      return int(random_str)
 30  
 31  
 32  def _generate_string(sep, integer_scale):
 33      predicate = random.choice(_GENERATOR_PREDICATES).lower()
 34      noun = random.choice(_GENERATOR_NOUNS).lower()
 35      num = random.randint(0, 10**integer_scale)
 36      return f"{predicate}{sep}{noun}{sep}{num}"
 37  
 38  
 39  def _generate_random_name(sep="-", integer_scale=3, max_length=20):
 40      """Helper function for generating a random predicate, noun, and integer combination
 41  
 42      Args:
 43          sep: String separator for word spacing.
 44          integer_scale: Dictates the maximum scale range for random integer sampling (power of 10).
 45          max_length: Maximum allowable string length.
 46  
 47      Returns:
 48          A random string phrase comprised of a predicate, noun, and random integer.
 49  
 50      """
 51      name = None
 52      for _ in range(10):
 53          name = _generate_string(sep, integer_scale)
 54          if len(name) <= max_length:
 55              return name
 56      # If the combined length isn't below the threshold after 10 iterations, truncate it.
 57      return name[:max_length]
 58  
 59  
 60  _GENERATOR_NOUNS = [
 61      "ant",
 62      "ape",
 63      "asp",
 64      "auk",
 65      "bass",
 66      "bat",
 67      "bear",
 68      "bee",
 69      "bird",
 70      "boar",
 71      "bug",
 72      "calf",
 73      "carp",
 74      "cat",
 75      "chimp",
 76      "cod",
 77      "colt",
 78      "conch",
 79      "cow",
 80      "crab",
 81      "crane",
 82      "croc",
 83      "crow",
 84      "cub",
 85      "deer",
 86      "doe",
 87      "dog",
 88      "dolphin",
 89      "donkey",
 90      "dove",
 91      "duck",
 92      "eel",
 93      "elk",
 94      "fawn",
 95      "finch",
 96      "fish",
 97      "flea",
 98      "fly",
 99      "foal",
100      "fowl",
101      "fox",
102      "frog",
103      "gnat",
104      "gnu",
105      "goat",
106      "goose",
107      "grouse",
108      "grub",
109      "gull",
110      "hare",
111      "hawk",
112      "hen",
113      "hog",
114      "horse",
115      "hound",
116      "jay",
117      "kit",
118      "kite",
119      "koi",
120      "lamb",
121      "lark",
122      "loon",
123      "lynx",
124      "mare",
125      "midge",
126      "mink",
127      "mole",
128      "moose",
129      "moth",
130      "mouse",
131      "mule",
132      "newt",
133      "owl",
134      "ox",
135      "panda",
136      "penguin",
137      "perch",
138      "pig",
139      "pug",
140      "quail",
141      "ram",
142      "rat",
143      "ray",
144      "robin",
145      "roo",
146      "rook",
147      "seal",
148      "shad",
149      "shark",
150      "sheep",
151      "shoat",
152      "shrew",
153      "shrike",
154      "shrimp",
155      "skink",
156      "skunk",
157      "sloth",
158      "slug",
159      "smelt",
160      "snail",
161      "snake",
162      "snipe",
163      "sow",
164      "sponge",
165      "squid",
166      "squirrel",
167      "stag",
168      "steed",
169      "stoat",
170      "stork",
171      "swan",
172      "tern",
173      "toad",
174      "trout",
175      "turtle",
176      "vole",
177      "wasp",
178      "whale",
179      "wolf",
180      "worm",
181      "wren",
182      "yak",
183      "zebra",
184  ]
185  
186  _GENERATOR_PREDICATES = [
187      "abundant",
188      "able",
189      "abrasive",
190      "adorable",
191      "adaptable",
192      "adventurous",
193      "aged",
194      "agreeable",
195      "ambitious",
196      "amazing",
197      "amusing",
198      "angry",
199      "auspicious",
200      "awesome",
201      "bald",
202      "beautiful",
203      "bemused",
204      "bedecked",
205      "big",
206      "bittersweet",
207      "blushing",
208      "bold",
209      "bouncy",
210      "brawny",
211      "bright",
212      "burly",
213      "bustling",
214      "calm",
215      "capable",
216      "carefree",
217      "capricious",
218      "caring",
219      "casual",
220      "charming",
221      "chill",
222      "classy",
223      "clean",
224      "clumsy",
225      "colorful",
226      "crawling",
227      "dapper",
228      "debonair",
229      "dashing",
230      "defiant",
231      "delicate",
232      "delightful",
233      "dazzling",
234      "efficient",
235      "enchanting",
236      "entertaining",
237      "enthused",
238      "exultant",
239      "fearless",
240      "flawless",
241      "fortunate",
242      "fun",
243      "funny",
244      "gaudy",
245      "gentle",
246      "gifted",
247      "glamorous",
248      "grandiose",
249      "gregarious",
250      "handsome",
251      "hilarious",
252      "honorable",
253      "illustrious",
254      "incongruous",
255      "indecisive",
256      "industrious",
257      "intelligent",
258      "inquisitive",
259      "intrigued",
260      "invincible",
261      "judicious",
262      "kindly",
263      "languid",
264      "learned",
265      "legendary",
266      "likeable",
267      "loud",
268      "luminous",
269      "luxuriant",
270      "lyrical",
271      "magnificent",
272      "marvelous",
273      "masked",
274      "melodic",
275      "merciful",
276      "mercurial",
277      "monumental",
278      "mysterious",
279      "nebulous",
280      "nervous",
281      "nimble",
282      "nosy",
283      "omniscient",
284      "orderly",
285      "overjoyed",
286      "peaceful",
287      "painted",
288      "persistent",
289      "placid",
290      "polite",
291      "popular",
292      "powerful",
293      "puzzled",
294      "rambunctious",
295      "rare",
296      "rebellious",
297      "respected",
298      "resilient",
299      "righteous",
300      "receptive",
301      "redolent",
302      "resilient",
303      "rogue",
304      "rumbling",
305      "salty",
306      "sassy",
307      "secretive",
308      "selective",
309      "sedate",
310      "serious",
311      "shivering",
312      "skillful",
313      "sincere",
314      "skittish",
315      "silent",
316      "smiling",
317      "sneaky",
318      "sophisticated",
319      "spiffy",
320      "stately",
321      "suave",
322      "stylish",
323      "tasteful",
324      "thoughtful",
325      "thundering",
326      "traveling",
327      "treasured",
328      "trusting",
329      "unequaled",
330      "upset",
331      "unique",
332      "unleashed",
333      "useful",
334      "upbeat",
335      "unruly",
336      "valuable",
337      "vaunted",
338      "victorious",
339      "welcoming",
340      "whimsical",
341      "wistful",
342      "wise",
343      "worried",
344      "youthful",
345      "zealous",
346  ]