Telegram Group & Telegram Channel
Сделал вчера неочевидный баг в простом коде и какое-то время тупил, это ли не повод оставить задачку для уважаемых подписчиков?

Задача такая: из некоторого списка тегов отбираем наиболее важные по словарю рангов, формируем промпт и отправляем в модель. Что не так с этим кодом?

import typing as t


def predict_from_tags(model: BertModel, tags: t.Sequence[str]):
prompt = prompt_from_tags(tags, model.tag_ranks)
return model.predict(prompt)


def prompt_from_tags(tags: t.Sequence[str],
tag_ranks: t.Dict[str, float],
max_tags: int = 20,
allow_duplicates: bool = False,
) -> str:

if not allow_duplicates:
tags = list(set(tags))

sorted_tags = sorted(tags, key=lambda x: tag_ranks.get(x, float("inf")))
return " ".join(sorted_tags[:max_tags])

Автор первого правильного ответа в комментариях не получит ничего, кроме респекта от таких же любопытных, которым зачем-то интересно просто так искать баги в чужом коде.



group-telegram.com/partially_unsupervised/185
Create:
Last Update:

Сделал вчера неочевидный баг в простом коде и какое-то время тупил, это ли не повод оставить задачку для уважаемых подписчиков?

Задача такая: из некоторого списка тегов отбираем наиболее важные по словарю рангов, формируем промпт и отправляем в модель. Что не так с этим кодом?

import typing as t


def predict_from_tags(model: BertModel, tags: t.Sequence[str]):
prompt = prompt_from_tags(tags, model.tag_ranks)
return model.predict(prompt)


def prompt_from_tags(tags: t.Sequence[str],
tag_ranks: t.Dict[str, float],
max_tags: int = 20,
allow_duplicates: bool = False,
) -> str:

if not allow_duplicates:
tags = list(set(tags))

sorted_tags = sorted(tags, key=lambda x: tag_ranks.get(x, float("inf")))
return " ".join(sorted_tags[:max_tags])

Автор первого правильного ответа в комментариях не получит ничего, кроме респекта от таких же любопытных, которым зачем-то интересно просто так искать баги в чужом коде.

BY partially unsupervised


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/partially_unsupervised/185

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

The S&P 500 fell 1.3% to 4,204.36, and the Dow Jones Industrial Average was down 0.7% to 32,943.33. The Dow posted a fifth straight weekly loss — its longest losing streak since 2019. The Nasdaq Composite tumbled 2.2% to 12,843.81. Though all three indexes opened in the green, stocks took a turn after a new report showed U.S. consumer sentiment deteriorated more than expected in early March as consumers' inflation expectations soared to the highest since 1981. The picture was mixed overseas. Hong Kong’s Hang Seng Index fell 1.6%, under pressure from U.S. regulatory scrutiny on New York-listed Chinese companies. Stocks were more buoyant in Europe, where Frankfurt’s DAX surged 1.4%. There was another possible development: Reuters also reported that Ukraine said that Belarus could soon join the invasion of Ukraine. However, the AFP, citing a Pentagon official, said the U.S. hasn’t yet seen evidence that Belarusian troops are in Ukraine. The fake Zelenskiy account reached 20,000 followers on Telegram before it was shut down, a remedial action that experts say is all too rare. Telegram users are able to send files of any type up to 2GB each and access them from any device, with no limit on cloud storage, which has made downloading files more popular on the platform.
from hk


Telegram partially unsupervised
FROM American