text:
Formally, what are the layers in an Artificial Neural Network?
You may not believe it, but I am an ANN expert. Perhaps, for that reason, I am unable to grasp completely what the layers are in a Deep Forward Artificial Neural Network (DFANN).
According to the Deep Learning "bible", p. 164 "the model is associated with a" directed acyclic graph (DAG) "describing how the functions are composed together". Then it states that one of these functions $f^{(i)}$ is a layer. We know that an ANN is composed of neurons/units (the biological perspective) and a DAG is composed of nodes/vertices and edges/links. A trivial mapping can be established between (neural) units and nodes, and (neural) connections and edges (see also Fig. 6.2 in p. 170). However, defining the layers in a DAG is not that trivial, I would say.
In a quick internet search, I came across about the concept of graph drawing and layering algorithms. This concept is never mentioned in the ANN literature. If I understood well, formally, we would need such an algorithm to be able to define the layers in the DAG.
A more intuitive description is given by AIMA: DFANN "are usually arranged in layers, such that each unit receives input only from units in the immediately preceding layer". That sounds indeed like a layering algorithm.
So, formally, what are the layers in an Artificial Neural Network?
As a side note, a practical argument is given by https://cs231n.github.io/neural-networks-1/

One of the primary reasons that Neural Networks are organized into layers is that this structure makes it very simple and efficient to evaluate Neural Networks using matrix vector operations.

That's nice, but only from a practical perspective.
An interesting remark has been made by Chillston (see comments, I quote):
That's because an FFN is not a general DAG but a very regular kind of DAG, right.
I also thought that could be the case. But Bishop, 1995, p. 116 contradicts us:

More generally we can consider arbitrary network diagrams (not
necessarily having a simple layered structure) since any network
diagram can be converted into its corresponding mapping function. The
only restriction is that the diagram must be feed-forward, so that it
contains no feedback loops.

As I see it, according to Bishop, any (general) DAG is indeed an ANN.

Can you specify your question or maybe describe what you mean exactly? From what I understand you are reasoning: An FFN is a DAG -> in a DAG the nodes cannot be trivially grouped into layers -> Neurons in an FFN cannot trivially be grouped into layers. Here, I would say that the way FFNs are constructed is very specific - i.e. one where this mapping from neurons to layers is trivial. That's because an FFN is not a general DAG but a very regular kind of DAG, right? If not what am I missing?

You are indeed in the right path. The way you describe it, is exactly what mean. I will consider to complete the question with your remarks.

One thing that evades me a bit still the underlying reason for the question. Lets say you have a case of an ANN where a mapping from individual neurons to layers is not trivial. (When you think about it, maybe even the transformer is such a case because of the interactions of encoder and decoder and residual connections?). I cannot yet see why thinking about this neuron-to-layer mapping is useful. What would such a mapping be useful for, and, what conclusions could you draw if this mapping is non-trivial? I hope its clear what I mean.

Well, regarding Q. No. 1, one could ask the same for every aspect of research and science, especially in graph theory and topology.
The 2. Q. is a little more perturbing because it uses the argument of utility (Utilitarianism?) to establish the importance of the matter.
Philosophical discussions apart, my motivation in asking this question is rather banal. I am writing my dissertation and I realized that I was unable to connect the arguments fluently. The details would need several pages, so I will stop here.
I almost found the answer, but I have to double-check it before I post it.

Sure, the main reason why I was asking that is that a questions sounds a bit confusing if such details aren't clarified (i.e. that this is an explorative question with yet unknown utility). I wish you success with the diss and have my fingers crossed for a positive outcome of this investigation. Also I am actually curious about your argument and in case you find some interesting properties regarding the layering question, maybe you can drop a link or summary ;)

In a practical point of view, a "layer" in a neural network is a step in computation which only depends on its preceding layers' outputs. Note that layer $n$ might take inputs from any previous layers, not only from $n-1$. Those are called skip connections. But since you are an expert, I assume you know all this already.
Usually NNs are defined as a stack of layers, which define a DAG. But given a DAG, there are several valid layer-by-layer interpretations of its structure. But in general, I don't think it is important to know whether a given node is from layer $i$ or $j$. May I ask, what is the motivation behind this question?

Thanks for the answer. As you stated, I am aware of all the facts you mentioned.

@neoglez Ok, but then it's hard to believe that you're an expert and you are still confused about the concept. If this answers your question, you should accept it. If it doesn't then you should ask for clarifications. What's still confusing?

@nbro Please note, that the discussion ist not about whether I am expert or not. If you cerefully read the information you linked to, you can see that an answer can be accepted, when the answer satisfies the question, which ist unfortunately not the case.

@nbro well, we can be experts in any field - relatively speaking. But usually an expert don't call himself one, in an believe-it-or-not tone. Beside, we should be careful when spelling the word "cerefully".


text:
Is whisper.ai non-deterministic?
I am experimenting with Whisper AI sound-to-text (actually I am using the whisper.cpp clone right now) and am trying to optimize the performance but I have discovered something odd - although I use exactly the same setting every time except for the number of threads, the result isn't exactly the same. In other words, the result varies depending on the number of threads.
Is this expected? If so, why does it happen?

Can you please provide a link to this Whisper AI?

@nbro Added links.

Yes, you can see a comment from discussion here:
https://github.com/openai/whisper/discussions/81

This happens when the model is unsure about the output (according to
the compression_ratio_threshold and logprob_threshold settings). The
most common failure mode is that it falls into a repeat loop, where it
likely triggers the compression_ratio_threshold. The default setting
tries temperatures 0, 0.2, 0.4, 0.6, 0.8, 1.0 until it gives up, at
which it is less likely to be in a repeat loop but is also less likely
to be correct.

I've seen also non deterministic results on audio that was clear. Even more than that it generates non related outputs. Using the whisper.ai API you can not play with the parameters but if you are using the open source models you can fine tune it a little bit to perform better.

I realised that if you use two threads it splits the sound into two pieces and lets one thread start from the beginning while the other thread starts from the middle. What happens with the second thread is that, that is different from using only one thread, it is missing linguistic context. That is, if you only use one thread, when you reach the middle of the sound file it has some understanding of the subject of the speech it transcribes which it uses when it interprets the speech, which (hopefully) improves the result. I think that is what happened in my case.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Should the Q-Value of a state-action tuple be updated, if $s_{t} == s_{t+1}$
Assuming the agent in my environment does an action, however the agent's state does not change. Does that mean the Q-Table gets updated regardless of respective states (current and next) being the same, or do we skip calculating a new Q-Value in this instance?

If the state not changing is a valid transition for the environment (e.g. due to an action result such as running into a wall in a maze, or just random chance), then yes it should be accounted for as normal in updates. After all, time is still ticking, and it will impact mean reward or discounted return calculations.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Is a small transformer model able to effectively handle any input length provided it is fine-tuned on it?
Suppose we have a transformer LLM which can do a task such as summarising.
I know transformer can technically handle any input length (assume we are not using learned positional embeddings) because the architecture doesn’t define a fix length for input. However, the quadratic complexity and unavailability of long text data puts a practical limit on sequence lengths used for training and they are not effective beyond the sequence length they are trained on.
Suppose we have enough hardware resources and data of a particular long input length. Will the model be able to perform the same task effectively on that, say, 1 million length? Or will we need a model with more parameters?
I would appreciate any reason or empirical result which shows this would or wouldn’t work. Also will this depend on the complexity of a task? If so why would the said complexity increase with input length?

Hi @Emoticon and welcome to AI Stack Exchange! If possible, please only ask one question per post. That way, your question is more likely to be answered more quickly. Thank you, and we hope to see more of your posts here soon!


text:
How to derive the variance of the forward step of Variational Diffusion Models in terms of the log signal-to-noise ratio $\lambda_t$?
Regarding Eq. (1) in Progressive Distillation for Fast Sampling of Diffusion Models,
$$
q(\mathbf{z}_t|\mathbf{z}_s) = \mathcal{N}(\mathbf{z}_t; (\alpha_t/\alpha_s)\mathbf{z}_s, \sigma _{t|s}^2 \mathbf{I})
\tag{1}
$$
, it says $\sigma_{t|s}^2 = (1 - e^{\lambda_t - \lambda_s})\sigma_t^2$.
I believe $\sigma_{t|s}$ is from DDPM's $\beta$, then it's equivalent to $1 - \alpha_t^2 / \alpha_s^2$ here. Note that $\lambda_t = \log (\alpha_t^2 / \sigma_t^2)$. As far as I understand, $\sigma_t^2 + \alpha_t^2 = 1$. Maybe I'm taking something wrong.
Anyway, how could $\sigma_{t|s}^2 = (1 - e^{\lambda_t - \lambda_s})\sigma_t^2$ be derived from $1 - \alpha_t^2 / \alpha_s^2$?
Some more notes.

More papers are using the same expression.

Classifier-Free Diffusion Guidance
Video Diffusion Models
Imagen Video: High Definition Video Generation with Diffusion Models

I think the definition of $\sigma_{t|s}$ Eq. (22) in the original VDM paper is straightforward with respect to DDPM's definitions.
The expression seems to be quite similar to Eq.(32) of VDM.

One of my colleagues gave me a solution. (Thanks Ken!)
$$
{\begin{aligned}
\sigma_{t|s}^2 &= 1 - \alpha_{t|s}^2 \\
&= 1 - {\alpha_t^2 \over \alpha_s^2} \\
&= {\alpha_s^2 - \alpha_t^2 \over \alpha_s^2} \\
&= {(1 - \sigma_s^2)-(1-\sigma_t^2) \over \alpha_s^2} \\
&= {\sigma_t^2 - \sigma_s^2 \over \alpha_s^2} \\
&= {\sigma_t^2 (\alpha_s^2 + \sigma_s^2) - \sigma_s^2 (\alpha_t^2 + \sigma_t^2) \over \alpha_s^2} \\
&= {\sigma_t^2 \alpha_s^2 - \sigma_s^2 \alpha_t^2 \over \alpha_s^2} \\
&= \left(1 -{\sigma_s^2 \alpha_t^2 \over \alpha_s^2 \sigma_t^2}\right) \sigma_t^2 \\
&= \left(1 -{1 \over e^{\lambda_s}}\cdot e^{\lambda_t}\right) \sigma_t^2 \\
&= \left(1 - e^{\lambda_t - \lambda_s}\right) \sigma_t^2 \\
\end{aligned}}
$$
given
$$
\alpha_t^2 + \sigma_t^2 = 1 \\
\alpha_{t|s}^2 + \sigma_{t|s}^2 = 1 \\
e^{\lambda_t} = {\alpha_t^2 \over \sigma_t^2}
$$
.

There is another derivation:
$$
{\begin{aligned}
\sigma_{t|s}^2 &:= \sigma_t^2 - {\alpha_{t}^2 \over \alpha_s^2} \sigma_s^2 \\
&= \left( 1 - {\alpha_t^2 \sigma_s^2\over \sigma_t^2\alpha_s^2} \right) \sigma_t^2\\
&= \left(1 -e^{\lambda_t}\cdot {1 \over e^{\lambda_s}}\right) \sigma_t^2 \\
&= \left(1 - e^{\lambda_t - \lambda_s}\right) \sigma_t^2 \\
\end{aligned}}
$$
given
$$
e^{\lambda_t} = {\alpha_t^2 \over \sigma_t^2}
$$
.


text:
Memory consumption issues during the validation phase/loop
Context:
I am trying to fine-tune codet5-base model for a use-case on AWS's g5.2xlarge instance, and the following were my original training parameters:
training_args = TrainingArguments(
        output_dir='sentiment_classification',
        learning_rate=1e-4,
        per_device_train_batch_size=8,
        per_device_eval_batch_size=8,
        num_train_epochs=2,
        weight_decay=0.01,
        evaluation_strategy='epoch',
        save_strategy='epoch',
        load_best_model_at_end=True
    )

I observed that the GPU memory consumption was constants until the first validation phase started. At the start of the validation phase, the memory consumption increased rapidly and torch process ended due to insufficient GPU.
I reduced the batch size for both, training and validation from 8 to 4. Same result!
Now, I optimised validation phase by introducing the following params:
        metric_for_best_model="accuracy",
        fp16=True,  # Enable mixed precision
        eval_accumulation_steps=10  # Accumulation steps for eval

Now the memory consumption during the validation phase was constant. But the towards the end of the validation phase, the process ended due to insufficient CPU.
To solve this, I reduced my size of validation dataset from 20% to 5%. Now the process successfully ran through the first validation phase and started the second epoch.
My Questions:

Since I haven't used any custom dataloaders, why is the training loop optimised by default (i.e., it is using constant GPU memory) and not the validation loop.

Even after introducing params like eval_accumulation_steps=10, the validation phase was killed due to insufficient CPU memory. There was enough empty/available GPU memory that could have been used instead of CPU.

Programming questions are off-topic here. See https://ai.stackexchange.com/help/on-topic.


text:
What's the relationship between Reinforcement Learning (RL) and Markov Chain Monte Carlo (MCMC)?
The title may seem too broad, let me specify this question a bit more.
Suppose that there is a problem that can be solved via MCMC-based algorithm, i.e., for its formulation we can construct a Markov chain, and Monte Carlo sampling is adopted to reach a desired stationary distribution.
If this MCMC algorithm has proved to work well, then is it possible that its Markov chain-based description of the problem can also be used to formulate an RL description?
If so, there is another more detailed question. Assuming that the acceptance probability in MCMC algorithm is calculated based on Metropolis-Hastings, say
$$
A(x^{\prime}, x)=\min (1, \frac{P(x^{\prime})}{P(x)} \frac{g(x\mid x^{\prime})}{g(x^{\prime}\mid x)}).
$$
What could the relationship of the transition model of an RL model and this acceptance probability be?

I don't really see much common ground between the two... one is used to sample a complex distribution, the other one traverse a distribution (state space) and either is used to learn a policy that optimize a reward, or in other cases just to estimate a gradient...

I agree that the two don't have much in common, but I just want to find out whether an existing MCMC algorithm could be regarded as a reference for formulating the problem as MDP, which RL model is usually based on.


text:
How to structure the input data for non-vision deep reinforcement learning?
I am currently designing a custom gym environment that is based on sensor data and I struggle a bit with structuring the data and designing the model. Virtually every resource I find online is kind of vision based, in the sense that it takes images as input arrays.
Data structure
For each time step, I get a couple of readings from each sensor. This would be an example reading from one sensor, with ... representing other variables.
{
  "temperature":"20.3",
  "humidity":"63",
  ...
}

Now I see two approaches how to structure the input array for a model (t being temperature, h being humidity):
[
 [t,h,...],
 [t,h,...],
]

[
 [t,t,...],
 [h,h,...],
]

Note that this represents the data for one time-step and is not representing a series of time-steps.
Question
Does it make a difference how I structure that data?

I'm gonna mark this for later because I think I can help, but it's late here

Hi @94621 and welcome to AI Stack Exchange! This stack exchange website seems to be very particular about asking a single question per post. If possible, please condense your questions into a single question. I know that it might be difficult, but this post will most likely be closed if action isn't taken. Thank you for posting, and we hope to see more of your questions on this site!

Thanks for the hint @DeepQZero. I will edit the question accordingly

Does it make a difference how I structure that data?

Since your gym environment creates two values, t and h at one single step, I believe the way you structure your input matters.
Let's start with this one:
[
 [t,h,...],
 [t,h,...],
]

If I understand correctly, the index of the list is the input at the i-th step, so your input at step 0 is inputs = X[0] = [t,h,...]. This is the correct way. Your model sees t and h at the same time, which is what your environment produces.
If you structure your input in the second way:
[
 [t,t,...],
 [h,h,...],
]

This way, it means your model sees t first, then sees h in the next step. This is technically incorrect from what we assume, since each input should be independent of each other. What's worse, I see that your t and h are on different scales, so it is highly possible that the training will diverge.
However, depending on the difficulty of the task (which we don't know), you might or might not see a big difference between two structures. However, I recommend sticking with the first one.

Thanks for your answer @minh-long-luu. I think my description is a bit ambiguous: The list I am describing is actually for one time-step, meaning that I have readings from multiple sensors per step. I will edit my question to make that more explicit.


text:
Why is my loss graph heavily fluctatuing?
I am working on a CNN project on an image dataset. I am applying Early Stopping technique in order to train the model. However, after training the model and obtaining the loss graph, it is heavily fluctuating, as shown in the image below. I have tried training the model more than once and I get a similar loss graph:

This is my model structure:

Therefore, is this a normal loss graph? If not, what may be the underlying issue and how can I solve it? I have read that regularization can solve this problem, but I am already applying Dropout. Is there anything else worth investigating?
Note that this is not really affecting my validation accuracy (accuracy on unseen data). It performs decently on it, with 93.3% accuracy.


text:
lyric search algorithm :prompt to real lyric
I want to make a lyric search tool.
In other words,it is means that give some prompts and get some lyrics which exist in the real world.
For example:
Input: some lyrics from coldplay ,give me power
Output:
Lights will guide you home
And ignite your bones
And I will try to fix you
I am a NLP newbie.And I want to use BERT to solve this problem but i don't know how to continue to do it.
My idea is bulid a structure as following:

And calculate  cosine similarity between output.
But it dosen't work well.
So I have another idea.
Powerful chatGPT can recommand lyric but it does not work well in other non-English language lyrics.
Now my idea is use chatGPT to generate a lyric, translate the generated lyric into a specified language, and then compare the generated lyric with the lyric datasets to select the most similar one.
But this method is complex and it's hard to guarantee the accuracy of the search.
Is there any better way？Is there another way to do this without chatgpt?
Or are there any similar papers?I only found the papers about ai generate lyric.

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.

What have you tried? What do you understand about BERT? We want to help you but you have to communicate with us.  The answer. Generally speaking is yes. I've written similar systems for searching legal text which is just as obtuse.
Do you know what a semantic embedding is?

@Conic Thank you for your comment. I added more details. I don't know semantic embedding.I'm going to learn it.Are there any recommended papers about semantic embedding ?

@AnshumanKumar Thank you for your comment. I added more details.

I tried it myself by giving the lyrics specifying the language and then, asking what comes after those lyrics. It also gives the translation. This can be solved using ChatGPT.
Coming to your other point. Yes, we can do it without ChatGPT. You just need to create good embeddings of the other lyrics and find similarity between them. You can do that with training models like BERT and adding ArcFace loss to them.
But, since you have ChatGPT, I wouldn't recommend that.


text:
Why does LLM inference cost scale in both input tokens and output tokens?
EDIT
This question was flawed. See my answer with help from commenters.

Original question
This question has been asked in other forums [1] [2] but I'm not sure I understand the claims, which are (EDIT: the following are based on my faulty assumption that pad tokens are added up to the maximum context window):

Each forward pass takes less resources when more of the context window is padding.
Forward passes are run on the input tokens.
Forward passes with fewer non-pad input tokens are smaller tensor operations.

Hypothesis 1 seems the most plausible to me from a performance engineering standpoint (sparse math, etc). Does it fall out naturally from just writing basic JAX code or would it require manual optimization (if so, what tricks can be used?)? There does seem to be some research on this.
Hypothesis 2 and 3 seem wrong based on my surface-level understanding of the Transformer architecture.
I've tried a few open-source LLMs locally and neither on those nor ChatGPT have I noticed any difference in latency based on how much text was in the context window. But I haven't done actual rigorous benchmarking yet.
The reason this is relevant is due to document lookup-based applications. Looking at the OpenAI cookbook for Q&A using embeddings, I can see that:

most of the token usage seems to come from the long Wikipedia article pasted into the context
the price per query is quite prohibitive to frequent usage:

For gpt-3.5-turbo using ~1,000 tokens per query, it costs ~0.002 per query, or ~500 queries per dollar (as of Apr 2023)
For gpt-4, again assuming ~1,000 tokens per query, it costs ~0.03 per query, or ~30 queries per dollar (as of Apr 2023)

My prior intuition would have been that optimal usage of LLMs would be to keep the context filled with inexpensive text (e.g. from NN search and/or cheaper LMs) and to have the LLM generate terse responses. But the input token cost model changes the strategy, as it means that users need to be sparing about the size and quantity of documents that they paste into the context window.

you have a (ignoring possible improvements from FastAttention) a modules that scales quadratically with the sequence length (attention), thus doubling the length, will x4 the cost of that... thus, it's expensive to have both an long input, and a long output (as words are generated autoregressively)

So with padding it does not do the full tensor dot?

Unfortunately, this is a bit opinion-based, so needs to be closed. Asking why companies charge you money is a bit opinion-based. Formulate the question to make it a theoretical question about AI. Please, change the title accordingly. Maybe the title is the only thing you need to reformulate.

The Transformer architecture doesn't require padding and can natively process variable-length input. Why do you think there are pad tokens added? (in practice it may be more complicated because one wants to batch multiple inputs)

One can only speculate about pricing decisions and furthermore, how OpenAI are batching requests. For example, they might well batch similarly sized requests together. This avoids a situation where most tokens in a batch are padding because one input is huge and the rest are small. Pad tokens are still expensive to calculate, so this is sensible. This  would mean shorter inputs are cheaper than long ones, due to lack of padding (not more of it).

OK, I understood now. If the input of dimension N_INPUT * N_VOCAB and N_INPUT is variable then that simply means Q, K, V, Z have one variable dimension (N_INPUT * D_ATTN_HEAD) and input/output of MLP are just N_INPUT * WIDTH. For some reason I thought there would be a mismatch in some matrix multiplication if N_INPUT is not fixed, but it turns out that N_INPUT is always the first dimension (except in the result of Q * K_T but since it is only multipled with V on the right which has first dimension N_INPUT it is okay) so this is not the case.

I guess this also makes the answers here wrong? https://ai.stackexchange.com/questions/37624/why-do-transformers-have-a-fixed-input-length?rq=1
With this question's answer being more correct: https://ai.stackexchange.com/a/37289/68775

Transformers can be run with a variable dimension N_INPUT as pointed out by @pcpthm's comment. That means that the answer to "Why do transformers have a fixed input length?" are wrong, and the answers to "How do transformers handle arbitrary-length input?" are more correct.
If the input of dimension N_INPUT * N_VOCAB and N_INPUT is variable then that simply means Q, K, V, Z have one variable dimension (N_INPUT * D_ATTN_HEAD) and input/output of MLP are just N_INPUT * WIDTH.
For some reason I thought the hidden layers would be fixed size and/or require a fixed size input, but this is not the case since it turns out that N_INPUT is always the first dimension, except in the result of Q * K^T which has dimension N_INPUT * N_INPUT, but is only multiplied on the right by V which has first dimension N_INPUT.
In the NNs that I'd learned about previously, N_INPUT is the second dimension so even if one were to put in a variable input, all of the hidden layers would still be fixed-size.
Particularly what I did not realize is that the "context window" is not actually a part of the model (except in the positional encoding). It seems to be purely a training time / inference time restriction.


text:
How to expand an agent's action space with more actions?
I'm training a FPS agent using StableBaselines 3's PPO algorithm.
To aid learning, I would like to train the agent using just a basic set of actions (e.g Turn left, turn right, shoot). After the agent has mastered that scenario, I'd want to expand the action space with the ability to move forward.
Additional actions would also be included later on, such as moving left, and right.
PPO has a check for matching action spaces, so just providing a new environment to the model doesn't work.
My final question is:
How can I expand the action space so that the PPO model doesn't reject the new agent?

Hi @Ilija Vuk and welcome to AI Stack Exchange! This post seems to contain multiple good questions, especially the 3 question at the end of the post. Typically, this stack exchange website aims to have a single question per post. If possible, please edit this post to a single question, and possibly ask other questions in a separate post. This will help the post conform to this site's guidelines and will probably help you receive an answer faster. Thank you for posting, and we are looking forward to more of your questions on this site!

You can use Maskable PPO, which is PPO but with support for invalid actions. In your case, you need to implement the method action_masks() by yourself, which returns True or False depending whether the action is invalid.


text:
How does transformer models like GPT generate valid meaningful response for meaningless garbage input?
My understanding of a transformer model is that it uses the given input to calculate internal query of relate-ness of word meanings, and generate a meaningful response based on its meaning. But if your given sentence has no meaning, then won't the model fail to capture any meaningful input so that the output will also be meaningless? How does the ChatGPT generate meaningful response asking me what I meant when the input is uncoordinated and meaningless? Is that a feature, or did they train on that kind of input specifically?
eg. Input "Jumps the dog lazy fox over quick brown the."
For the output, ChatGPT asks for clarification.
Normally for a self-attention based model, there won't be any relation between input word for this example, so shouldn't the output also be garbage like?

can you give an example of a garbage input and output that you do not understand?

If you give a human some input that doesn't seem to convey any meaning they will probably ask you for clarification. Presumably there are a lot of examples of this in the ChatGPT training data so that is exactly what it is going to do.


text:
Why use Deep Learning instead of algorithms for decision making in self-driving cars?
Let's say I want to build a self-driving car that uses cameras and ai to detect objects and driving lanes.
So if the camera detects e.g. a car in front, it calculates the distance (using a sensor) and passes that information to the algorithm which handles steering and acceleration.
Another example is parking. I could just write an algorithm that can park the car perfectly every time, instead of trying to train an ai, which would take a lot of time and computation.
Why would I use Deep Learning to make the car navigate instead of using a simple algorithm (like in video games) that can find the best path and steer accordingly?

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.

The real world is harder than a video game.

I could just write an algorithm that can park the car perfectly every time.

No you cannot. You may believe that you can, but you cannot. Real world data is too imperfect and complex.

Let's say I want to build a self-driving car that uses cameras and ai to detect objects and driving lanes.
So if the camera detects e.g. a car in front, it calculates the distance (using a sensor) and passes that information to the algorithm which handles steering and acceleration.

How do you propose "passing that information" to the algorithm? Raw camera data are images with pixels. What sort of algorithm could you construct that could drive based on raw camera input?
In short a human could never construct such an algorithm. It is beyond our abilities.
I also want to point out, deep learning IS an algorithm, just one learned from data.

I meant that the camera input could be processed by an ai that detects e.g. objects, but the steering would be handled by an algorithm using the information from the "camera ai"

@Mointy Did you say you can "write an algorithm that can park the car perfectly every time"? Please, sell it! You will be a millionaire in no time.


text:
Keypoint generation in 3D point clouds with Deep Learning
I have a huge dataset of 3D point clouds (each point consists of X,Y,Z coordinates) and another dataset with keypoints (also X,Y,Z) which lie on quite recognizable structures in the point cloud. As a human it is pretty easy to find these keypoint given the according point cloud.
There are 6-24 keypoints for each point cloud which may have up to 100.000 points but can be downsampled to fit into memory while processing.
My goal is to train a supervised deep learning model to detect/generate these keypoints in new point clouds. These have to be new synthetic points since the keypoints are most likely not in my point cloud.
Previously i tried to train a regression model using PointNet++ semantic segmentation. I generated weights for each point in the input point cloud according to its proximity to the next keypoint. For new point clouds the weights were predicted pretty well but it is very difficult to regenerate the synthetic keypoints from these weights since the area around the keypoint can be very sparse.
Essentially i am trying to use a model like this RSN on 3D point clouds to detect synthetic keypoints in the data. I thought about using object detection models like VoxelNet but these detect bounding boxes and i want to get a single predicted point as a result.
I am also wondering if its worth looking into GANs but i dont have experience with these models and until now i only found models who generate a whole new point cloud instead of a single points inside a given point cloud.
I would love to hear some ideas from you to point me in the right direction.

The previous milestone of your question is this*
You can use data stack that it has low resolution as S(Yn) of stream from supervised network for verifying. No data transfer loss with this rule:
S(Xn) ≥ S(Yn) > S(Xn)/2
Each time you change tether provider that network model before transform data stacks for the default stream or more data stack may be required because less finite sub-states in the supervised network will not be a factor in diagnosis.
There is an invert ratio between signal complexivity of X and process accuracy in S(Yn) ≤ S(Xn)/2 rule.

As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Unfortunately I do not understand your answer either. Your linked post is also inaccessible..

Hmm... Link is broken. It fixed.
If can help you this, Yn is your check data in one process time. Obtain check data by new tether before decode this by referencing first tether in every process time. Y is your check data stack and syntesis doors by this. This dynamic to be more successful than using static tethering methods because doors have exceptions of finite sub processes that they can not detected approximately.

You can use mathjax on this site!

Rules are not providing my requirements on this site. You can delete those


text:
Increasing "output_sequence_length" in TextVectorization layer worsens model's performance
When exploring the Twitter Sentiment Analysis dataset on Kaggle, I came up with a model that looks like this:
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #
=================================================================
 text_vectorization (TextVec  (None, 15)              ***
 torization)

 embedding (Embedding)       (None, 15, 200)          ***

 lstm (LSTM)                 (None, 100, 100)          ***

 dropout (Dropout)           (None, 100, 100)          ***

 lstm_1 (LSTM)               (None, 50)                ***

 dense (Dense)               (None, 3)                 ***

 dense_1 (Dense)             (None, 3)                 ***

=================================================================
Total params: ***
Trainable params: ***
Non-trainable params: ***
_________________________________________________________________

This model performs okay both in training and on validation (accuracy could reach to 100% for both). However, when I changed the output length of the input sequence in the first layer's (i.e the embedding layer) from 15 to 100, then its performance became worse. In fact, its accuracy could hardly reach 50% and training was also very slow. Here you can find the updated version of the model and related code.
Examining the data, I found that roughly 44.5% of training examples have lengths greater than 100.  So I guess it's not unreasonable to pad or truncate sequences to length 100. Also some sources say that we could pad all sequences to the length of the longest sequence in dataset and 100 is clearly not the longest sequence's length in this case.
So are there some guidelines or best practices for choosing the value for this parameter?

If you are just changing the output sequence length, its performance drop is understandable because the batch size, learning rate, dropout rate, etc. was tuned for the 15 words length. When changing the configuration, we must search new hyperparameters.

This type of issue happens for several other network architectures as well. Whenever I lower down the output sequence length, it always helps speedup convergence & increase accuracy. So my best guess is: it should not relate much to other hyper-parameters.

I cannot find the paper studying the Sequence length in LSTM, however you can have a look at a similar paper that studied it in the Attention mechanism. Figure 2 showed that the performance generally dropped after 20 words.


text:
No-Free-Lunch: Calculation of the number of sequences of examples of size $m$
In the proof of No-Free-Lunch Theorem from the book Understanding Machine Learning: From Theory to Algorithms Cambridge University Press, p.37-38, the author wrote:

Let $C$ be a subset of the domain set $\mathcal{X}$ of size $2m$.
...
There are $k = (2m)^{m}$ possible sequences of m examples from $C$.

I don't understand why the author came up with the number $k=(2m)^{m}$, my calculation turns out to be:
$$
\begin{align}C(2m, m)& = \frac{(2m)!}{m!(2m-m)!}
\\& =\frac{(2m)!}{m!m!}
\end{align}$$
And it doesn't come any close to $(2m)^{m}$ at all?

Your expression is "how many ways can I choose m unique elements from a list of 2m unique elements"
The author's expression is "how many unique sequences of length m can I construct from a list of 2m unique elements"
Let's take a small example. With m=2, and 2m elements {A, B, C, D}.
Your expression evaluates as 6, and those are the selections. AB, AC, AD, BC, BD, CD. No repetition, no permutations.
The author's expression evaluates as 16, and the sequences are AA, AB, AC, AD, BA, BB, BC, BD, CA, CB, CC, CD, DA, DB, DC, DD. Repetition included, all permutations separate.


text:
Why any set of m data points with different features can be perfectly fit by a polynomial of degree n as long as n ≥ m
On p.36 in "Machine Learning: The Basics", Alexander Jung, Spinger, the author wrote:

The fundamental theorem of algebra tells us that any set of m data points with different features can be perfectly fit by a polynomial of degree n as long as n ≥ m.

Where n is the length of the weight vector w in $\mathbf{R}^{n}$. To be specific, the hypothesis space is:
$\mathcal{H}^{(n)}_{poly} = \{h:R^{n} \rightarrow R:h(\mathbf{x})=\mathbf{w}^{T}\mathbf{x} \ with \ some\ vector\ \mathbf{w}∈\mathbf{R}^{n}\}.$
But I can't relate the fundament theorem of algebra to the existence of the hypothesis (or the weight vector). Can someone help to explain?

First, there's a mistake or typo in the quoted statement. The requirement should be $n \geq m-1,$ not $n \geq m.$ For instance, you can fit two points $(m=2)$ with a line $(n=1).$
Second, it's most straightforward to see this with simple linear algebra, not the fundamental theorem of algebra. I'll explain below.
In general, if you have a $n$th-degree polynomial $p(x) = a_0 + a_1 x + \ldots + a_n x^n,$ and you're fitting it to the set of $m$ data points $\{ (x_1,y_1), \ldots, (x_m,y_m) \},$ then you're trying to solve the following system of linear equations:
\begin{align*}
y_1 &= p(x_1) = a_0 + a_1 x_1 + \ldots + a_n x_1^n \\
&\vdots \\
y_m &= p(x_m) = a_0 + a_1 x_m + \ldots + a_n x_m^n \\
\end{align*}
Let's write this using vectors:
\begin{align*}
\begin{bmatrix} y_1 \\ \vdots \\ y_m \end{bmatrix}
=
\begin{bmatrix} a_0 \\ \vdots \\ a_0 \end{bmatrix}
+ \begin{bmatrix} a_1x_1 \\ \vdots \\ a_1x_m \end{bmatrix}
+ \cdots
+ \begin{bmatrix} a_nx_1^n \\ \vdots \\ a_nx_m^n \end{bmatrix}
\end{align*}
And simplify a bit:
\begin{align*}
\begin{bmatrix} y_1 \\ \vdots \\ y_m \end{bmatrix}
=
a_0 \begin{bmatrix} 1 \\ \vdots \\ 1 \end{bmatrix}
+ a_1 \begin{bmatrix} x_1 \\ \vdots \\ x_m \end{bmatrix}
+ \cdots
+ a_n \begin{bmatrix} x_1^n \\ \vdots \\ x_m^n \end{bmatrix}
\end{align*}
In other words, a solution exists if the $y$-vector is in the span of the $x$-vectors:
\begin{align*}
\begin{bmatrix} y_1 \\ \vdots \\ y_m \end{bmatrix}
\in \textrm{span} \left \{
\begin{bmatrix} 1 \\ \vdots \\ 1 \end{bmatrix},
\begin{bmatrix} x_1 \\ \vdots \\ x_m \end{bmatrix},
\cdots,
\begin{bmatrix} x_1^n \\ \vdots \\ x_m^n \end{bmatrix}
\right \}
\end{align*}
Since the $y$-values are arbitrary, this is equivalent to saying that the $x$-vectors span all possible $y$-vectors in $\mathbb{R}^m{:}$
\begin{align*}
\textrm{span} \left \{
\begin{bmatrix} 1 \\ \vdots \\ 1 \end{bmatrix},
\begin{bmatrix} x_1 \\ \vdots \\ x_m \end{bmatrix},
\cdots,
\begin{bmatrix} x_1^n \\ \vdots \\ x_m^n \end{bmatrix}
\right \} = \mathbb{R}^m
\end{align*}
You can span $\mathbb{R}^m$ with and only with a set of $m$ independent vectors in $\mathbb{R}^m.$ So, let's count off $m$ vectors:

The $1$st vector is $\begin{bmatrix} 1 \\ \vdots \\ 1 \end{bmatrix}$ which you can think of as $\begin{bmatrix} x_1^0 \\ \vdots \\ x_m^0 \end{bmatrix},$
the components of the $2$nd vector $\begin{bmatrix} x_1 \\ \vdots \\ x_m \end{bmatrix},$ i.e. $\begin{bmatrix} x_1^1 \\ \vdots \\ x_m^1 \end{bmatrix},$ have exponents $1,$
the components of the $3$rd vector (not shown above, but it would be $\begin{bmatrix} x_1^2 \\ \vdots \\ x_m^2 \end{bmatrix}$) have exponents $2,$
...
the components of the $m$th vector have exponents $m-1.$

So, we need $n$ to be at least $m-1.$

I think I understand your argument, it's very related to one of the results in Linear Algebra that I've learnt before about the (in)homogeneous system of equations (not Fundamental Theorem of Algebra). Also I think that $\mathbf{w}$ should have been a matrix of shape $mxn$, i.e $\mathbf{w} \in \mathbf{R}^{mxn}$, instead of a vector of length $n$?

The author's $\mathbf{w} \in \mathbb{R}^n$ is correct because $\mathbf{w}^T \mathbf{x}$ needs to be in the range of $h,$ which is $\mathbb{R}.$ If $\mathbf{w} \in \mathbb{R}^{m \times n}$ then there would be a dimension mismatch in the multiplication $\mathbf{w}^T \mathbf{x}$ (note that $\mathbf{x} \in \mathbb{R}^n$). And if $\mathbf{w} \in \mathbb{R}^{n \times m}$ then we would have $\mathbf{w}^T \mathbf{x} \in \mathbb{R}^m,$ not $\mathbb{R}.$

Justing gave an amazing answer, however I would like to give a more "empirical" way of looking at it
Say you have a 2D plane, you randomly set 2 point, then it's easy to see that you can intersect perfectly the 2 points with a line
Say you have a 3D plane, you randomly set 3 point, then it's easy to see that you can intersect perfectly the 3 points with a plane
Then you can just go and extend this to any dimension (losing the visual representation)
(Note: not always you can have this "generalization in N dimensions", but in this case it works, and it's correct)

As I pointed out in the comment, I think his answer implies that $\mathbf{w}$ should be in $\mathbf{R}^{mxn}$ instead of $\mathbf{R}^{n}$ as in the hypothesis formulation, is it correct?

@TranKhanh, no, a line $y=mx+b$ is constituted by 2 factors $m$ and $q$, a plane by 3 of them and so on, so it is in $R^n$


text:
Could you explain steps of proofs of policy improvement theorem in sutton & barto book?

I don't understand one step of the proof.
The equality means $\mathop{\mathbb{E}}[R_{t+2}+\gamma v_\pi(S_{t+2})|S_{t+1},A_{t+1}=\pi'(S_{t+1})]=R_{t+2}+\gamma v_\pi(S_{t+2})$
Could you explain the detailed steps of why the equality holds?

You seem to be missing a factor of $\gamma$ on the right hand side, or should remove it from the left hand side, of the equality you are questioning

Sorry for the confusion. I removed the gamma on the left side

This equality:

$\mathop{\mathbb{E}}[R_{t+2}+\gamma v_\pi(S_{t+2})|S_{t+1},A_{t+1}=\pi'(S_{t+1})]=R_{t+2}+\gamma v_\pi(S_{t+2})$

Does not hold in general, and in fact is not well-formed, because $R_{t+2}$ and $S_{t+2}$ are random variables following a distribution, whilst the expectation of the expression is a single real number.
However, the conversion works in the context of the outer expection, because the conditional part $S_{t+1},A_{t+1}=\pi'(S_{t+1})$ matches the outer expectation being $\mathop{\mathbb{E}_{\pi'}}$ i.e. the expectation over action choices made using $\pi'$. So the inner expectation, and its condition can simply be dropped because the condition on choosing the action using the new improved policy is the same as the outer expectation, just using different notation.
It is important that here the inner expectation is simply added to other terms. If it was multiplied by a variable term that it was dependent upon, the expression could not be unpacked from the inner expectation without affecting the result.

If so, I think the random variables $S_t$ and $A_t$ are the same as $S_{t+1}$ and $A_{t+1}$. So, the conditions of inner and other expectations are the same, so they can be dropped from inner expectation.

@teslo No those are different variables, the time step index difference is important. The reason it's the same condition is due to how those variables have been chosen. If it's not clear how they relate to the improved policy, and not the original one, I could add more about that to the answer

May I ask more details?

@tesio: Sure, but could you please say where you are stuck, or what you don't understand, so I can add the right details that help you?

Oh, I can't understand how they relate to the improved policy, and not the original one


text:
Dimensionality Limitations
I just started learning about AI and have been reading a book called "Foundations of Machine Learning" by Mehryar Mohri so that I can try to create my own. I had a question come up recently: Can I create a machine learning algorithm that can reasonably solve high dimensional problems?
For example, say I want to find a local maximum within a specified range for $Y$, but $Y$ is a function of $x_1,...x_{30}$ functions. And I call $x_i$ a function because it relies on all other $x$ functions such that for $x_{i=n}$, this is a function of all $x_{i \neq n}$. So there are 30 dimensions that the algo can alter and each variable is also a function of the other.
I looked up online about dimensional issues with AI and found a pretty good, simple article outlining why AI accuracy decreases with dimensionality increasing. The article was written a couple of years ago though and I wanted to see if anyone knew if research since then has found a machine learning method to get around this problem. If not, what are ways to say interpolate or minimize the error, besides a ton of training data or what the article recommends: dimensionality reduction prior to training?
PS - Please delve into the applied analysis that underlies whatever answer you may have!

"Solve" is kinda a harsh word here, but if it is "approximate", then I belive we have "kinda" solve it. For an image, it is reasonable to say that each pixel is one dimension, so a 224x244 image is already 50k dimensions. Recent advances in approximating the Image->Class function is pretty good.

@Minh-LongLuu I can see that since each pixel is itself a function of the color map or RGB value. However, that is a more simple example since each pixel technically isn't dependent on each other when it's fed to an algo (I would think). But also, perhaps some are. Like the art AIs I've seen I would think that in order for them to even remotely work, they would need to take into account both the local (subset of pisxels) and global (total set of pixels in image) pixel RGB values to produce something coherent.

Assuming pixels have neighbor relationship is something we...assume. There is possibly no proof of it yet


text:
Where to find the source code for the research paper "Attention is all you need"?
I am reading "Attention is all you need". I have seen the following link:

Source: https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf
But when I go to https://github.com/tensorflow/tensor2tensor, there are too many folders without a guide. Where do you find the source code for the research paper "Attention is all you need"?

You may find the code related to the paper at https://paperswithcode.com/paper/attention-is-all-you-need.

Another resource to find all code related to the paper "Attention is all you need" is https://www.catalyzex.com/paper/attention-is-all-you-need/code. You can find this under the Code tab on ArXiv too.


text:
Higher accuracy in the test set than in the training set
Hi I'm trying to train an ANN model to classify images containing these characters: 0,1,2,3,4,T,X,S
eg.

etc...
so something like the classification of records of the MNIST dataset but using my generated images (not handwritten).
I generate ~10000 records that have to be divided in the training set and in the test set:
n = 10000
X_train, y_train = generate_typed(typed_alphabet_resized.astype('uint8'), int(n*0.8))
X_test, y_test = generate_typed_test(typed_alphabet_resized.astype('uint8'), int(n*0.3))

generate_typed and generate_typed_test are pretty much the same function, the sole difference is the augmentation applied to images:
for generate_typed_test the only augmentation applied is scale(1,3) while for generate_typed:
augmentation_seq = iaa.Sequential([
    iaa.Sometimes(0.3, iaa.GaussianBlur(sigma=(0, .1))),
    iaa.Sometimes(0.3, iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.2)),
    iaa.Affine(scale=(1, 3)),
], random_order=True)

I did that to make the model more generalized as possibile.
But really the kind of images the model is supposed to work on in the real world might just (sometimes) be zoomed in or be slightly less centered.
However even if I use these two different functions, the images I got are very very similar.
Now, the problem is: I got a bigger accuracy on the test set than on the training set, and I really can't understand why and how to fix it.
It seems like that the accuracy of my model doesn't matter, if my model has around 80% of accuracy or 95% of accuracy, I still got an 0.9997 on test set (bigger than the accuracy during the training).
Note: Even if I apply the same type of trasformations on the train and test set, or if I apply no trasformation to both sets nothing changes.
I'm not saying the model doesn't work, but it's really wrong quite often.
I don't know if this means overfitting or not, but I don't think so because loss & accuracy doesn't intersect each other:

Model:
model3 = Sequential([
  Flatten(input_shape=(28,28,1)), # "appiattisco" l'immagine
  Dense(20, activation='relu'), # creo uno strato denso la cui funzione di attivazione è relu
  Dropout(0.5), # Spengo a caso dei neuroni (per evitare overfitting)
  Dense(num_classes, activation='softmax') # strato denso di 10 neuroni con funzione di attivazione softmax (perchè è un classificatore)
])

model3.compile(
    loss = 'sparse_categorical_crossentropy',
    metrics=['accuracy'],
    optimizer=Adam(lr=0.01)
)

X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.1, random_state=42)
model3.fit(X_train, y_train, epochs=5, batch_size = 5, validation_data=(X_val, y_val), callbacks=[early_stop])

_________________________________________________________________
 Layer (type)                Output Shape              Param #
=================================================================
 flatten_34 (Flatten)        (None, 784)               0

 dense_71 (Dense)            (None, 20)                15700

 dropout_37 (Dropout)        (None, 20)                0

 dense_72 (Dense)            (None, 105)               2205

=================================================================
Total params: 17,905
Trainable params: 17,905
Non-trainable params: 0

Your test set images are more clean than your training set images, because you applied more types of noise to the training set images, so the classifier performs better on the cleaner images in the test set.
I don't see why this is surprising.

Yeah , sorry if I forgot to specify that: if I apply the same trasformation to images (or no trasformation at all) I got the same result, a bigger accuracy in the test set than on the training set, I'm going to make an edit to the question

Getting higher accuracy in test set than in training set means that your test set is easier to work on than training set. Your graph shows results for only one epoch. In the 1st epoch, your train accuracy/loss will include the learning phase when loss was high whereas by the time evaluation happens, the model has already learned. Is the behaviour same in subsequent epochs?
As you mentioned that you get similar results even with same or no augmentation, ignoring the learning phase issue, it is possible that your training set has more samples for which the network doesn't perform well, dragging the performance down. You can test this using something like k-fold cross validation which tests your network on multiple train-test pairs.


text:
Best feature engineering approach for interest-based age classification
I have a dataset which has users (rows) with the list of their interests (IABs), which looks like this
user_id | gender | list of interests
--------+--------+--------------------------------
user 1  | male   | games, productivity
user 2  | female | games, lifestyle, design
user 3  | male   | travel, games, messaging
user 4  | male   | messaging, blogging, lifestyle
...

Since the number of unique interests are few (~500) and the number of rows are high (~67M), what are the feature engineering practices that I should follow to get an ML model score a better accuracy?
P.S.: Simple model with one hot/count hot vectorization yields an accuracy of ~52%

Your title suggests a question about metric but your question is asking about feature engineering for fixed metric (accuracy). Please update either the title or question

@SajanGohil updated the title

Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.


text:
How could chatGPT avoid consuming what it produces
Considering the popularity of chatGPT, we can imagine that in the near future, many people will use it to produce lots of text contents on the internet, like blogs, forums. The productivity will be significantly improved.
However, I have a worry that the produced text content will be consumed someday in the future by chatGPT as part of the corpus. So it raises a problem, the AI will study tons of self produced text as new material.
So, is there a mechanism for chatGPT or any other chat bot to avoid that technical vicious circle?

If it reads what it writes and so on at least doesn't burn our time. What worries me more is humans having to produce what it consumes or us having to read what it writes.

An effort to distinguish content from good content.
One of the major complaints about ChatGPT (certainly you'll see this all over Stack Exchange sites) is that it tends to deliver low quality answers. Which makes sense. It's just a language model. Its answers are, therefore, definitely language. Just not necessarily accurate and detailed responses to a given query. As such, I think you would very rarely see ChatGPT generated content being very popular or upvoted (even if it wasn't outright banned).
I think that's the sort of thing that a training session should try to take into account: not "what is the source of this" but "is the source popular, well liked, or notable".
If you were training ChatGPT from Stack Exchange input, then an obvious first step would be to have it skip anything with low numbers of views or low number of upvotes. SE is already telling you which questions and answers are low quality, so avoiding those is a good idea, and this would also, I believe, incidentally keep a chatbot from ingesting other chatbot output (because the typical rambling, vaguely off-topic chatbot outputs would rarely make it into the "high quality" category).
Similarly, you don't know if a website is created by a chatbot, but if you can gauge its notability or appeal, you can at least try to make a judgement about if it's worth using as a training source. Not notable? Not by a known author? Low page view count? Unknown website? Skip it.
Basically, just don't train a chatbot by having it willy-nilly go through the entire internet A-Z. The inputs need some curation. The more you can steer it away from low quality inputs, the better its training will be and, incidentally, the more likely it is to avoid inputting previous rounds of low quality chatbot output.


text:
Adding a Transposition Table to Monte Carlo Tree Search
I think I'm having a bit of trouble wrapping my head around how a transposition table functions:
As I understand it you can store a value (simulation result?) for a given game state in this (hash) table and use it instead of a simulation when that game state is encountered again. However, since the simulation is (or at least in my case is) completely random play, I would think that you need to build up a sample size before the result value of the simulation starts meaning anything.
It seems to me that with the way I understand it now, these two principles can't both be achieved simultaneously, so what am I missing?
As a side note I have come across some information that suggests changing the valuation algorithm to account for the transposition table and have done so (hopefully correctly).

I have had a chat with ChatGPT which helped me wrap my head around it:
An important factor here is that my simulation (also called a rollout) consists of random play. Because of this I need ot visit this state and pplay randomly for many times in order to be able to somewhat accurately estimate the value of the position.
The aim of adding a transposition table is to save computation of states that have already been evaluated before. But you can store multiple evaluations before skipping the simulation and reusing the value once your confidence in it is high enough. It depends on the game and the size of the search space and most importantly the way you achieve the game value (random play simulation vs for example a neural network as alpha zero does it) how large that number needs to be.
Another important aspect I learned is that you need to persist the table and use it for later games. If you don't it will not be effective, because you only save the states in the past which you likely will not encounter (there are some exceptions like both players putting a piece back sequentially). So essentially it becomes a dataset.


text:
How do temperature and repetition penalty interfere?
I'm trying to demystify my understanding of various decoding parameters. Building on our understanding of temperature, how does the repetition penalty interfere with temperature?
For example, does something special happen when the penalty is approximately equal to temperature, or approximately its reciprocal? Does the penalty need to be offset or biased based on the temperature?

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.

TL;DR: Temperature is applied after repetition penalty, so it smoothes out its effect.
They are basically independent hyper-parameters of the decoding, but applied after each other.
Higher temperature makes the output distribution more uniform, so you are likely to get more diverse generations, but at the same time, you risk they will not make sense (in an extreme case, you might even get malformed words).
Language models, especially when undertrained, tend to repeat what was previously generated. To prevent this, (an almost forgotten) large LM CTRL introduced the repetition penalty that is now implemented in Huggingface Transformers. It is described in an unnumbered equation in Section 4.1 on page 5:

It discounts the probability of tokens that already appeared in the generated text, making them less likely to appear again.
Discounting already generated words is implemented as a RepetitionPenaltyLogitsProcessor, and temperature is implemented as TemperatureLogitsWarper in the Transformers library. Processors get applied before Warpers. This means that the effect of discounting of already generated tokens gets smoothed by the temperature smoothing.

This is not a bad introductory answer, and I'll upvote it, but I was very much hoping for something which notices e.g. that when temperature and repetition penalty are equal in Transformers, then they cancel each other out!

@Jindfich I'm having trouble seeing how the formula from the paper incorporates previous words.  The formula looks remarkably similar to the formula for when just the temperature is accounted for.  But maybe I'm not interpreting the i and j suffixes correctly?


text:
Can DeepSort be made to track objects beside people?
As far as my understanding goes, the model used for feature extraction in DeepSort is specified as the first argument of the function create_box_encoder in the file tools/generate_detections.py:
def create_box_encoder(model_filename, input_name="images",
                       output_name="features", batch_size=32):
    image_encoder = ImageEncoder(model_filename, input_name, output_name)
    image_shape = image_encoder.image_shape

    def encoder(image, boxes):
        image_patches = []
        for box in boxes:
            patch = extract_image_patch(image, box, image_shape[:2])
            if patch is None:
                print("WARNING: Failed to extract image patch: %s." % str(box))
                patch = np.random.uniform(
                    0., 255., image_shape).astype(np.uint8)
            image_patches.append(patch)
        image_patches = np.asarray(image_patches)
        return image_encoder(image_patches, batch_size)

    return encoder

In the same file, the default value of the argument model_filename is specified under the parse_args() function to be resources/networks/mars-small128.pb, which appears to be a model for person re-identification.
Can a model for re-identifying objects other than people (and from multiple classes, such as cars, birds, trucks, etc) be used instead in DeepSort? If so, does DeepSort provide any means for training such models?
My initial understanding was that DeepSort would be able to track all classes recognized by a trained YOLO model. I didn't know that a stand-alone feature extractor was required.

In my experience, if you have really discriminative objects with distinct features then yes! The original DeepSORT's reid model can be borrowed to track those things.
But for the best result, you should train your own reid model to suit the task and the classes that you want to track.

By DeepSORT's original reid model do you mean the default resources/networks/mars-small128.pb?

Yes, that's correct :D

Isn't that model only trained for extracting people features, and thus won't work on other objects?

Theoretically, yes. But in reality, it CAN BE BORROWED because kernel filters that learned  to extract people feature can still have different reactions to different features from unseen data. From those information, model might can still know something and patchworkly embbed those features in its embedding space.

You said that I should train my own reid model to have better results. Do you have something that can get me started? I'm relatively new to this and so I'm basically lost when it comes to what is normally done in these cases.

Sure, at first if you are new to this field, you can try re-train the base OSNet model.
For the next step, you could try replacing the backbone in the architecture with newer backbone for better feature extraction.
Furthermore, you can read related papers to understand better about the reid task, I would recommend you read more about metric - contrastive learning (Arcface, SubArcface, InfoNCE,...) and some training strategies (self-supervised, SupCon,...).
Finally, learn and learn more. Expand your knowledge base so you can come up with many ideas to work on and improve your result.


text:
Was ChatGPT trained on Stack Overflow data?
Has ChatGPT used highly rated and upvoted questions/answers from Stack Overflow in its training data?
For me it makes complete sense to take answers that have upwards of 100 upvotes and include them in your training data, but people around me seem to think this hypothesis doesn't make sense. Is there a way to confirm this?

It's worth noting that even with the option you suggest, the answers produced by ChatGPT wouldn't be more correct. Maybe they would be slightly better written, but this is not the issue.

Think about the attrition this inbreeding will cause to the quality of SO answers.. People ask ChatGPT for solutions which come in part from SO, then they post the answers to SO, ChatGPT learns from these answers but doesn't get them perfect, so the next time someone asks ChatGPT for a similar answer, the result is a little more incorrect, and is then again posted to SO..

@tplive. That's exactly the reason SO has a feedback system. In my experience, the answers supposedly knowledgeable people post are often no walk in the park.

It certainly didn't learn from stackexchange to apologize for its mistakes.

If the responses are often condescending or unhelpful then 'yes'

ChatGPT is in the Large Language Models (LLM) category. The most (in)famous GPT model is probably GPT-3, because since then, researchers realized that LLMs mostly follow a predictable scaling law, thus the more data and the bigger model, the better. It is accurate to say that ChatGPT was trained with Stack Overflow data, but it should be all Stack Overflow instead of just most upvoted answers/comments.
The Wikipedia page of GPT-3 and their paper mentions that GPT-3 was trained on multiple datasets, and one of which is the Common Crawl, which basically crawls everything on the Internet. Some data pre-processing was done before training, but the authors did not mention removing the comments, so we can say that it is all Stack Overflow data.
If we look at the Common Crawl data in Sep 2022, there is indeed the domain com.stackoverflow in their list. Thus, while ChatGPT was trained on Stack Overflow data, it is trained on all Stack Overflow data instead of just most upvoted answers.
However, if you think ChatGPT's code output is of high quality, think again, because Stack Overflow temporarily bans ChatGPT because the average rate of getting correct answers from ChatGPT is too low, the posting of answers created by ChatGPT is substantially harmful to the site and to users who are asking and looking for correct answers (quoted from the link).
Here is the justification of them:

The primary problem is that while the answers which ChatGPT produces have a high rate of being incorrect, they typically look like they might be good and the answers are very easy to produce. There are also many people trying out ChatGPT to create answers, without the expertise or willingness to verify that the answer is correct prior to posting. Because such answers are so easy to produce, a large number of people are posting a lot of answers. The volume of these answers (thousands) and the fact that the answers often require a detailed read by someone with at least some subject matter expertise in order to determine that the answer is actually bad has effectively swamped our volunteer-based quality curation infrastructure.

EDIT: a comment below also confirmed that GPT-2, the predecessor of GPT-3 and ChatGPT, was trained with Stack Overflow data.

How do you know it was trained on all data? The crawler might have accessed all data. But how do we know this data hasn't been preprocessed? E.g. remove comments etc.

@ThomasWeller See Appendix A of the paper. I don't think they removed comments.

Note that because the average rate of getting correct answers from ChatGPT is too low is not sourced in the link you've provided.

I would argue that (at least in the general population), ChatGPT is now the most famous GPT model, by quite a large margin.

@Arthur yes, I would agree so, but I believe it is because ChatGPT is now publicly available, while GPT-3 was not (and is still not), making it extremely unpopular compared to ChatGPT. If only it was publicly released like GPT-NeoX, it could have the fame of NeoX and dominated the world's press

It is also known that GPT2 was trained on Stack Exchange, and Stack Overflow.

Technically speaking, we don't know whether ChatGPT used Stack Overflow data for the training.
That is because ChatGPT is a proprietary model, and OpenAI hasn't published training details to the public.
We know that, from the GPT-3 paper [1], the GPT-3 training dataset includes Common Crawl. However, there is no indication of the relation between GPT-3.5 series (including ChatGPT) and GPT-3 models according to OpenAI's account.
See also this question Are GPT-3.5 series models based on GPT-3? for the discussion on GPT-3 vs. GPT-3.5.
I add: the token set is different between davinci (GPT-3) and text-davinci-003 (GPT-3.5) (source) thus the later cannot be a simple fine-tuning of the former.
I think, though, it is natural to infer OpenAI uses StackOverflow data because it is generally considered high quality [2] and easily obtainable. Also, if OpenAI ever uses web crawling data, it will see many StackOverflow and its clone sites.

[1]: T Brown et al. "Language Models are Few-Shot Learners." NeurIPS (2020).
[2]: Guilherme Penedo et al. "The RefinedWeb Dataset for Falcon LLM: Outperforming Curated Corpora with Web Data, and Web Data Only." arXiv preprint (2023).

it was trained using supervised from open ai team for initializing the conversational model and for more customize style, it can highly possible using chosen stackoverflow sample dataset since the answer of the question from the website was moderated. ChatGPT was take the advantage of GPT-3 model that has been trained from various corpus of data and can perform few-shot learning.

As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.


text:
Training a neural network to produce a one-hot encoding vector out of a single feature
I would like to build a neural network that takes a natural number and generates a one-hot encoding vector corresponding to that number.

Example: $2 \rightarrow (0,0,1,0,\dots)$

More formally, I want it to take an input $i \in [0, \dots, K]$ and produce an output vector $(o_0, \dots, o_j, \dots, o_k)$, where all $o_j$ are 0, except $o_i$, which is 1 (i.e. one-hot encoding).
However, I am not sure on what the specific architecture should be. I believe it should have more than one layer, since there is no linear relationship between the input and the output.
I have tried several architectures, but the best performance I have been able to get is 33%. I am using the following code:
import pandas as pd
import torch
import torch.nn as nn
import torch.optim as optim
from sklearn.model_selection import train_test_split
import random
random.seed(0)
torch.manual_seed(0)

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(1, 55)
        self.fc2 = nn.Linear(55, 30)
        self.fc3 = nn.Linear(30, 25)
        self.relu = nn.ReLU()
        self.dropout = nn.Dropout(p=0.2)
        self.softmax = nn.Softmax(dim=0)

    def forward(self, x):
        x = self.fc1(x)
        x = self.relu(x)
        x = self.dropout(x)
        x = self.fc2(x)
        x = self.relu(x)
        x = self.dropout(x)
        x = self.fc3(x)
        x = self.softmax(x)
        return x

net = Net()

# A list of 10000 random numbers between 0 and 24
dataset = pd.DataFrame([random.randint(0, 24) for _ in range(10000)])
dataset['label'] = dataset[0] # The label is the same as the input

train, test = train_test_split(dataset, test_size=0.2)

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(net.parameters(), lr=0.001)

for epoch in range(5):
    # Train
    running_loss = 0.0
    for i in range(len(train)):
        inputs = train.iloc[i, 1:].tolist()
        inputs = torch.tensor(inputs, dtype=torch.float)
        labels = train.iloc[i, 0]
        labels = torch.tensor(labels, dtype=torch.long)

        optimizer.zero_grad()
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()

    # Evaluate
    correct = 0
    total = 0
    with torch.no_grad():
        for i in range(len(test)):
            inputs = test.iloc[i, 1:].tolist()
            inputs = torch.tensor(inputs, dtype=torch.float)
            labels = test.iloc[i, 0]
            labels = torch.tensor(labels, dtype=torch.long)
            outputs = net(inputs)
            predicted = outputs.argmax()
            total += 1
            correct += (predicted == labels)

    print('Accuracy of the network on the test set: {:.2f}%'.format(100 * correct / total))

I believe my task is pretty simple, but I just can't think of the right architecture to do it. Do you have any ideas? :)

I'm not familiar with pandas but how does this dataframe layout work? Is this training with only 1 number per batch?

Yup, I checked that and it's working :)

It is training with only 1 number per batch?

There's no batching here, to be more specific...

I think this generally leads to suboptimal training unless the learning rate is set very low. In each training step the network converges towards whichever number was presented in that step, with nothing making sure the other numbers also keep working.


text:
How does censorship work in ChatGPT?
My assumption is that after the transformer is trained, some other software analyzes the answer for anti-wokeness and modifies it accordingly, rather than being trained using woke material.
I don't think this is correct though. I asked ChatGPT  to answer every question by inserting a $ (dollar sign) character in between each character of the otherwise normal answer, to make it unreadable, or at least, difficult to interpret by what I call the censorship layer. The output had these inserted characters; however, this had no effect on the censorship. But maybe the censorship layer is smart enough to read in between lines.
Question: Does the censorship come from within the transformer or after it? (and, if it comes after, why did my attempt to bypass it fail?)

This is impossible to answer because there is no publicly available information about inner workings of ChatGPT.

There is no way to know why your personal attempts to bypass the filters have failed, and it is a ridiculous question since you have given no details about what you've attempted. Additionally, the question is deliberately inflammatory by using "woke" as some sort of aspersion. There is nothing "woke" about making a tool publicly available to children not write erotica or use racist epithets. While the question has attracted one unsourced answer about a proprietary system, that may or may not be correct, the overall question certainly does not live up to SE's standards in multiple ways..

Dr. Snoopy is correct - any answer to this question as it is currently posed is mere speculation, unless somebody from OpenAI is willing to respond and provide actual insider knowledge. I would encourage you to reword this in such a way that it's not asking for information that is basically "unavailable by definition".
Ben I. is also correct. I'd encourage you to drop the use of "woke" as a pejorative and keep this neutral and mostly technology focused. Otherwise this is at risk of being closed.

Censorship in OpenAI's GPT models is implemented at the post-processing stage, after the model has generated its response. The censorship policies and criteria are defined by OpenAI, and they are applied to the output of the model before it is displayed to the user. The policies and criteria are designed to prevent the generation of harmful, abusive, or otherwise inappropriate content. The exact details of how censorship is implemented and enforced by OpenAI are proprietary and not publicly disclosed.

Thanks, did you read the paragraph before the question? What motivated the question was not really answered. That is my mistake though, I should have explicitly stated that in the italics. I edited it.

"There is no censorship mechanism within the transformer.". It answered GPT-3 itself.

I would not trust GPT-3 answers. Also, you didn't address my question: why my attempt to bypass it failed?

Even with old mechanisms like word2vec it was really simple to identify clusters of offensive words, all in the same vector spaces. I think GPT-3 is trained to avoid those clusters in the answer or recognizing questions with answers falling in those dangerous spaces. So, I think it's all inside the transformers and there isn't a way to bypass it. It creates "polite" answers and then adds the special character $ to the text.

Can you provide a source that supports this claim "Censorship in OpenAI's GPT models is implemented at the post-processing stage". I know OpenAI has some kind of "moderation" API, but I'd like to see some sources that support any claim about ChatGPT, because we see a lot of speculation.


text:
How does a LLM (transformer) pick words from its vocabulary?
I have a very rough understanding of the "attention/self attention" mechanism of transformer models and how this can be used to process a set of word vectors provided as an input/prompt to the encoder of a network and how this will produce "attention weights" for the word vectors based on positional encodings and some other learnable parameters (key/query/value transforms). And then these can be "fed" to the decoder part of the network which will also consider word vectors that have been produced by the decoder so far and influence word selection by paying special attention to particular word combinations.
However LLMs clearly produce words in their output/response that do not occur anywhere inside the "prompt" text. So they must be using these "attention weights" to consider words from a wider vocabulary, which could be quite large.
Is it the case that the decoder "considers" each possible word in it's entire vocabulary when producing an output word? For example I'm imagining an input layer to a NN with several thousand nodes (one per word vector in dictionary) on the input then these are "combined" through some operation with attention weights (from the encoder and decoder "attention section") producing values for most word vectors that are very low (so below the threshold for some activation function) but each word is still "considered" to an extent? Or are only a subset of words considered in some way?

All LLMs have a fixed vocabulary of tokens. In the simplest case, a token is a word. This means words not in the vocabulary cannot be output. Modern LLMs have a tokeniser that converts text into tokens. The raw output of the LLM is in tokens. These are strung together to form sentences. There is some additional work to convert a distribution over tokens into a predicted sentence. The simplest model is to choose the token/word with the highest probability in each position. That may yield nonsensical outputs. Real-world LLMs do some clever searching and post processing.

I guess this picture is not quite right: "And then these [attention weights?] can be 'fed' to the decoder part of the network which will also consider word vectors that have been produced by the decoder so far and influence word selection by paying special attention to particular word combinations."
The general picture I have learned goes like this:

One-hot word vectors are sent through the embedding matrix $W$ and yield lower-dimensional word embeddings.

In each decoder layer the word vectors are enriched by the attention mechanism, but only by contextual information from previous tokens ("masked attention").

So the first token doesn't get enriched at all, its information content remains the same.

The last token takes up the maximum of information available and after the last decoder represents the context as a whole.

It's only the enriched word embedding (= context embedding) of the last token that is now sent through the transpose $W^T$ of the word embedding matrix (the final decoder, different from the transformer decoders). It yields the logits vector.

Other models than GPT may use other final decoders than $W^T$.
The following diagram depicts this. The shades of gray of the word vectors passed through the transformer decoders display their informational content (or density).

After forwarding the prompt through the whole transformer architecture, the output is forwarded through one final linear layer.

"This final linear layer maps the output of the model back to the size of the 'vocabulary'. I.e. if you want to predict the next letter in a message, it would map to 26 (letters) + additional stuff (such as .,-!? etc.)."

For each possible output token, it predicts the probability (between 0 and 1) that that token is the next token. For models such as GPT-4, this last linear layer maps to a 10.000+ dimensional output (it includes arabian/chinese/japanese etc tokens).
Regarding your question:

Is it the case that the decoder "considers" each possible word in it's entire vocabulary when producing an output word?

Yes. Each output token is considered as a possible option.


text:
cross_val_score of sklearn and LinearRegression scoring method
The function cross_val_score uses the estimator’s default scorer (if available) and LinearRgression (the estimator I use) uses The coefficient of determination (which  is defined as $R^2 = 1 - \frac{u}{v}$, where
$u$ is the residual sum of squares ((y_true - y_pred)** 2).sum() and
$v$ is the total sum of squares ((y_true - y_true.mean()) ** 2).sum().
The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a score of 0.0.)
Is y_true.mean the y_true.mean of the training set or the testing set? If it's the one of the testing set, isn't it "cheating" i.e. we compare our predictions to a method that has inferred something from the testing set?
So doing better than a baseline wouldn't be having $R^2 > 0$ but rather $R^2 > -0.01$ or something like this?

You have model.score(x_test, y_test). Then it computes $R^2$ according to $\hat{y}=model(x_\text{test})$. $u$ accounts for the predictions, whereas $v$ represents an ideal situation in which $\hat{y}$ is the same as y_test (i.e. no errors).  You do the ratio of that, so what's the issue?

From my understanding $v$ represents the situation where I predict the mean, not a situation with no errors? (otherwise $v$ would be $0$ and you'd be dividing by $0$)

The cross_val_score function of the sci-kit-learn library uses the test dataset's mean to calculate the R2 score during each cross-validation fold. This is not called cheating since the R2 score is designed to evaluate how well the model is performing generalized on new unseen datasets and using the test set's mean is a standard part of the R² calculation.
you are right about it y_true.mean is from the testing dataset but it is not cheating because R2 > 0 means the model performs better than a constant baseline that predicts the mean of the test dataset.
If your model can't beat this simple baseline, it means the model isn't effectively learning the relationship between the input features and the target.
The baseline comparison is not meant to "cheat" by using information from the testing set; rather, it is a fair baseline that checks if your model is doing better than simply predicting the average of the testing set’s target values.
Should R² > -0.01 Be the Baseline?
Not really. The baseline you are competing against is R² = 0, which is the score of a constant model that predicts the mean of y_test. A score below 0 means the model is performing worse than simply predicting the mean of the test data, but R² > 0 is the standard for doing better than a baseline model.
I am not going much deep into the interpretation of the r2 score like what the value of r2 suggests about the model results since Luca Anzalone has explained well in above answer
for the question So doing better than a baseline wouldn't be having R2>0
but rather R2>−0.01
or something like this?
=> No, doing better than the baseline is indicated by having an R² score greater than 0. it is due to following reasons
An R² score of 0 means that your model performs as well as a constant model that predicts the mean of the target values from the test set, ignoring the input features.
An R² score greater than 0 means your model is doing better than the baseline (constant mean prediction).
An R² score less than 0 means your model is doing worse than the baseline.
If your model had an R² score of something like -0.01, that would imply that the model's predictions are slightly worse than just predicting the mean of the test set. But the true goal is to have R² > 0, which indicates that your model is leveraging the features to make predictions that outperform the simple mean baseline.
if you have still doubt feel free to ask and also ignore some notation mistakes since i am new at typing notation on stack :)

but if my R² is exactly 0 it means I was able to do as well as if I had access to the mean of the test set, without having access to the test set, so I should expect a "pat on the back", not a score of 0, right?

R² = 0 means your model’s predictions are no better than simply predicting the mean of the test set . While it’s true that you didn't "cheat" by using the test set directly, R² = 0 means your model’s predictions are no better than simply predicting the mean of the test set  While it’s true that you didn't "cheat" by using the test set directly since the R² score is designed to answer: "How well does my model use the input features to predict the target variable? R² = 0 doesn't punish you, but it reflects that your model hasn't added value beyond predicting the test mean.

Ok, so one should still not be unhappy if R² = 0, it would mean that one has learnt $\epsilon > 0$ about the task at hand with the training set. I would hence expect that the strategy of 'taking the mean of the output variable of the training set to predict the output variable in the test set' would on average get me R² < 0. Is this really desirable?

Yes you are right   Achieving R² = 0 does indicate that your model is doing at least as well as predicting the test set’s mean, even though you don't have access to it. That means your model has indeed learned something about the task at hand using the training data. So, in a practical sense, you're not in a bad spot if R² = 0 — it just reflects that you're not yet improving over the baseline using the input features.

If you use the strategy of predicting the mean of the output variable from the training set for the test set, you're right to suspect that this could often result in an R² less than 0. because R2 means the generalization of the model its formula compares the model results with the baseline of the mean of the test set R² < 0 indicates that your model is worse than simply predicting the mean of the test set. This happens because your model's training-set-based predictions don't fit the test set as well as the constant mean baseline would

for your question  Is this desirable?  In the context of model evaluation, yes, this is desirable — the way R² is structured serves a purpose to encourage the improvement since it is made for the improvement of the generalization of the model and it is also Punishes overfitting or underfitting  R2<0 happens when your model is not performing well on new dataset because of the underfitting and the overfitting, so it gives you hint about overfitting or underfitting.

Thanks! can't award bounty just yet but will do when i can

Ok No issue , if you have still doubt on that feel free to ask :)

Let's clarify this with a numerical example. Let's assume y_true = [0, 1, 1] to be the true class labels of $N=3$ test points. Therefore, y_true.mean() = 2/3.
Case 1: everthing is wrongly predicted, so y_pred = [1, 0, 0]. Let's compute $u$ and $v$.
$$
\begin{align}
u &= \sum(y_\text{true}-y_\text{pred})^2 = (0-1)^2+(1-0)^2
+(1-0)^2 = 3 \\
v &= \sum \Big(y_\text{true}-\frac23\Big)^2 = (-2/3)^2+(1/3)^2+(1/3)^2 = \frac69 = \frac23
\end{align}$$
Now we compute $R^2$, so:
$$R^2 = 1 - \frac{u}{v} = 1 - \frac{3}{2/3} = 1 - 2 = \mathbf{-1}$$
You get -1 because y_pred is always wrong. so you can think of $u$ as counting the number of errors (it's so if you predict the label to be exactly zero or one), whereas $v$ is the ratio of positive labels.
Case 2: perfect predictions, so y_pred = y_true.
$$
\begin{align}
u &= (0-0)^2+(1-1)^2
+(1-1)^2 = 0\quad\quad\text{(no errors)} \\
R^2 &= 1 -\frac{0}{2/3} = 1
\end{align}$$
$R^2=1$ because every label is correctly predicted, so there are no errors and the correlation is the most possible.
Case 3: some errors, say y_pred=[0, 1, 0]. Again:
$$
\begin{align}
u &= (0-0)^2+(1-1)^2
+(1-0)^2 = 1 \\
R^2 &= 1 -\frac{1}{2/3} = 1 - \frac32 = -\frac12
\end{align}$$
$R^2=-0.5$, so negative correlation. From this it seems that $R^2$, in general, gives more importance to correctly predicting the positive class.
So, there is no issue about using the mean of the true labels because that info is not used during training but only to compute an evaluation metric.

Maybe my post wasn't clear but I'm talking about cross_val_score which evaluates the coefficient of determination on the testing set?

I see. cross_val_score takes a model and a dataset ($X$, $y$). It trains the model $k$ times, each time leaves out (for validation) a "fold", and then computes the score (e.g. $R^2$) on that fold. You use cross_val_score to validate your model, so $(X, y)$ is actually the training set not the test set (otherwise you "cheat"). Once you determined the best model you retrain it on all the train-set, and do the final evaluation on test (e.g. by computing $R^2$). Read here for more.

I see. But when computing the score (e.g. $R^2$), it does use y_true.mean in v, right? y_true.mean being the mean of the testing fold.

You perform cross_val_score on $(X_\text{train},y_\text{train})$, so for each fold (there are $k$ of them) you have $(X_\text{train}^k,y_\text{train}^k)$ and $(X_\text{val}^k,y_\text{val}^k)$. Evaluation is performed on the latter pair, and y_true.mean refers to $y_\text{val}^k$. You do this, see the results and if satisfied you finally evaluate on the test-set: you don't use cross_val_score otherwise it would train on test data which is wrong, but instead use r2_score

I see, you don't use cross_val_score to get the the coefficient of determination of your method. But, to get the coefficient of determination of your method, you calculate it on the test-set. However, I believe my questions still stand. The y_true.mean is now $y_{test}$ right? So when calculating the coefficient of determination on the test-set, v depends on the mean of the test set. So if $R^2_{test}$ is equal to 0 it means we do as well as a method that inferred a little bit something from the test set (y_true.mean) so we learned a little more than just noise?


text:
Reverse Process in Diffusion Model Doesn't Return Original Image
I am attempting to program a Denoising Diffusion Model based on the one introduced in the article by Ho et al. (2020). However, I have run into issues while testing the reverse diffusion process.
Walking through my PyTorch code, I first load an image x, which I normalize, and generate a fixed noise tensor e ($\epsilon$) the same size as x. I also define a noise schedule with 10 steps, where a and d correspond to $\alpha$ and $\overline\alpha$ in the paper. The calls to unsqueeze and view are only to make the dimensions compatible for the computations that follow.
x = read_image("data/in/dog.jpg").unsqueeze(0) / 255 * 2 - 1
e = torch.randn(x.shape)
a = torch.linspace(0.9, 0.5, 9).view(-1, 1, 1, 1, 1)
d = a.cumprod(0)

Then, I gradually apply noise to the original image, concatenating each new sample along the first dimension. This process follows the recommended formula $x_t = \sqrt{\overline\alpha_t} x_0 + \sqrt{1 - \overline\alpha_t} \epsilon$.
for t in range(9):
    x = torch.cat((x, d[t].sqrt() * x[0] + (1 - d[t]).sqrt() * e))

This results in a gradual noising process, as expected.

Next, I attempt to remove the noise using the formula $x_{t-1} = x_t - \frac{\sqrt{1 - \alpha_t}}{\sqrt{\alpha_t}} \epsilon$, derived from $x_t = \sqrt{\alpha_t} x_{t-1} + \sqrt{1 - \alpha_t} \epsilon$.
for t in range(8, -1, -1):
    x = torch.cat((x, (x[-1:] - (1 - a[t]).sqrt() * e) / a[t].sqrt()))

This, however, has a strange result. It seems that the image is being denoised up to a certain point, but starts getting noisier thereafter.

I believe that this is due to $\epsilon$ in the formula $x_t = \sqrt{\overline\alpha_t} x_0 + \sqrt{1 - \overline\alpha_t} \epsilon$ not being the same as in $x_t = \sqrt{\alpha_t} x_{t-1} + \sqrt{1 - \alpha_t} \epsilon$. However, it seems to make sense that the denoising process would deterministically lead to the original image when the noise $\epsilon$ applied at each time step is known. Why is this not the case?
EDIT: After a lot of fiddling around, I have managed to use the formula $x_{t-1} = \frac{1}{\sqrt{\alpha_t}} x_t + \frac{1 - \overline\alpha_t - \sqrt{(1 - \overline\alpha_t)(\alpha_t - \overline\alpha_t)}}{\sqrt{1 - \overline\alpha_t}\sqrt{\alpha_t}}\epsilon$ to correctly predict the reverse diffusion process. This, however, raises more questions than answers. I notice that the formula resembles that of the mean of the ground truth decoder $q(x_{t-1}\vert x_t, x_0)$, $\mu_q(x_t, x_0)=\frac{1}{\sqrt{\alpha_t}} x_t + \frac{1 - \alpha_t}{\sqrt{1 - \overline\alpha_t}\sqrt{\alpha_t}}\epsilon$, but is not equal to it. What is going on here?


text:
If weights and biases are in superposition state, do we still need backpropagation algorithm?
Deep learning is basically finding the best weights and biases in order to reduce loss that is computed by the defined loss function to be as small as possible (global minimum).
Finding the global minimum was not an easy task, and it seems there is no algorithm yet to check whether current weights and biases are in the global minimum or local minimum for all possibilities of weights and biases.
Gradient descent basically returns an output of reference for the weights and biases to tune their values. Hence, it's possible that the model will be stuck in local minima due to the optimizer thinking there's already a global minimum (while it's not).
But what if we set the weights and biases value in superposition state with a quantum computer?
That's to say we will always reach global minimum by computing loss function output in superposition state due to the consequence of superposition state at weights and biases.
Does it mean we don't need gradient descent anymore?
In another word, the weight initialization in superposition state and n-times measurement observed are considered learning processes.


text:
Is vanishing gradient and exploding gradient coming from practical constraint rather than theoritical?
As the gradient is flowing back propagated from the output layer (last layer) into the input layer (first layer) that passed through multiple hidden layers by the chain rule, it's intuitively enough that the gradient reference of the previous layer is dependent on the next layer gradient reference.
There are two possibilities for how the gradient will change: vanishing gradient, where the gradient gradually becomes smaller (which leads to a to a small weight update), and exploding gradient, where the gradient gradually becomes higher (which leads to a to a higher weight update).
Practically, a gradient (which is just a number) is represented in IEEE 754 floating point; the precision depends on the maximum bit they had, e.g., float64. If the gradient range theoritically has range -5 to 5 for an architecture, then there must be wasted bits used, e.g., there are another 2^15 possible value that the value never reached.
So, if the gradient becomes smaller and smaller, like 10^-99, then one-bit changes can make slightly different values of the gradient, which distracts the overall computation.
But if we practically have a hardware constraint that considering the minimum of bit 000...00 is considered as -5 from domain-specific knowledge and the maximum of bit 111...111 is considered as 5, then the vanishing gradient will never exist since all bits are used efficiently.
In general, if there are infinity bits that carry more information, then there must never be such a thing as a vanishing gradient.
I tried with numpy, and it shows that the $-ln(\epsilon) \neq \infty $, but limited to relatively small number.
print(-np.log(np.finfo(np.float16).eps))
print(-np.log(np.finfo(np.float32).eps))
print(-np.log(np.finfo(np.float64).eps))

Resulting:
6.93
15.942385
36.04365338911715

For $log_2$, we have pretty round number:
print(-np.log2(np.finfo(np.float16).eps))
print(-np.log2(np.finfo(np.float32).eps))
print(-np.log2(np.finfo(np.float64).eps))

10.0
23.0
52.0

That round number I guess from number of mantissa bit size of IEEE 754.
This is critical for loss function calculation that using logarithmic scale such as categorical crossentropy.

you just need gradients with norms in the 10^-5 to have vanishing gradient, the problem is the number of steps it takes to do the optimization, not if IEEE754 can represent them


text:
Is there such generative model that drawing idealized version of dataset?
Suppose there are dataset of handwritten digit of zero. We know that human handwritten are not perfects. But here the model will tries to draw the ideal version of the digit, e.g. perfect circle.
Because I accidentally trained GAN where all random latent vectors input is almost identical to the idealized version of dataset. But for number 7 instead of 0.

Turns out if we feed the generator part without discriminator with real samples and random latent, we got idealized version of the dataset.