looked at in general learning from from relatively large data sets and it's worth mentioning that actually this particular approach up here was actually done was was one of the approaches that was used in the 90s and and also by hawk radar at all in 2001 but some of the approaches that we'll be discussing in later parts of the tutorial are more new another question from the audience was can we use meta learning approaches to solve classical supervised learning problems and are there any benefits to doing so so I think that we'll get to this


question a bit at the end there are situations where I guess the main thing the main type of problem that you want to be able to address with meta learning techniques is settings where you want to be able to take in information about a task that has that takes on the form of some data whether it be fully supervised or weekly supervised and so if your supervisor problems setting doesn't have that sort of structure where you want to learn from data to solve new problems then I think it would be quite challenging to apply some of these

Learning to learn: An Introduction to Meta Learning


techniques but in other situations maybe your meta learning maybe your supervised learning problem does have that structure and these approaches would definitely but definitely do well ok so let's move on to the optimization based approaches so now that we just kind of talked about one way to kind of make this approach more scalable is there a way to infer all of the parameters of the neural network in a way that's scalable without having to train a neural network to output all of the parameters in a particular as Sergei


mentioned before you can view the problem of supervised learning as an inference problem where I goes in for a set of parameters using data and the way that we solve supervised learning problems is through optimization and these optimization perches are quite scalable so what if we treat the problem of inferring a set of parameters from data and using meta parameters as exactly an optimization problem and and this is what optimization based approaches do and so the key idea here is that we're going to acquire our task


specific parameters Phii through an optimization procedure that depends both on the training data and our meta parameters theta and the optimization will look something like this where we are optimizing objective that looks like the likelihood of the data given our toss parameters as well as the likely of our task parameters given our meta parameters we're essentially the meta parameters are serving as a prior now you might ask well what should the form of the prior be for our meta parameters well there's a lot of different


approaches a lot of different things that we could do here but one very successful form of prior knowledge that we've seen in deep learning for example is using is training from an initialization provided by another data set and in particular what we seen is if we train on things like image and then fine-tune that model on other data sets were able to capture a lot of the rich information and supervision that's exists in the image that data set and use it for new tasks so this is a very successful form of prior knowledge


and of course the way that it works is you have a set of pre trading parameters data and you run gradient descent using training data for your new tasks okay so this is this works really well in a number of different situations but what if your train data for your new task has only a few data points like the six data points that I showed in the example at the beginning well in this case things like fine tuning are gonna break down a bit because though they weren't actually trained for the ability to adopt very


quickly and as a result you'll either over fit to those six examples or you won't be able to adapt quickly enough and move far enough from your initialization so this is what we want to be able to do a test I may be quite nice if we can just run fine tuning on on our six examples and get a get it up get some answer some function so this what we wanna be able to do at test time the key idea behind this approach is to explicitly optimize for us how to pre train parameters such that fine tuning with a very small data set works very


well and so what this looks like is we're going to take the fine tuning process written here this is just one step of gradient descent but you could also use a few steps or up to like ten steps of green descent for example then we are going to take where we were after got after fine tuning this can be like Phii for example evaluate how well that generalizes to new data points for that task this is measuring how successful fine-tuning was and then we can optimize this objective with regard to the initial set of parameters so we're gonna


optimize for set of pre train parameters such that fine tuning gives us a generalizable function for that task and of course we don't want to just do this over one task but we'll do this over all of the tasks that are meta training data set so that we can learn an initialization that's amenable to fine tuning for many different types of tasks ok so the key ideas is to learn this parameter vector that transfers effectively via fine tuning ok so what does this look like at a somewhat more intuitive level say theta is the the


parameter vector that we're meta-learning and Phi I star is the optimal parameter vector for task I am then you can view the meta learning process as a thick black line where when we're at this point during Mediterranean we take a gradient step with respect to task 3 we're quite far from the optimum for task 3 whereas at the end of meta learning if we take a gradient up with respect to toss 3 or quite close to the optimum and likewise for a number of other tasks we refer to this procedure as model agnostic medal earning in the


sense that is agnostic to the model that you use and loss function that you use as long as both of them are amenable to gradient based adaptation okay so now that we've gone through the objective again let's let's go through what actually that algorithm looks like so we can take the algorithm that we showed before for the standard for the the black box adaptation approach and instead we want to derive the algorithm for an optimization based approach and what we can do is we can simply just replace step 3 that's inferring the parameters with the


neural network with a step that's actually optimizing for the parameters in this case through gradient descent so we'll sample a task sample destroy its data sets for that and for parameters with gradient descent on the training data and then update our meta parameters using the test data points note that this does bring up a second-order optimization problem because you have to compute the gradient in step four you have to differentiate through a gradient step and test in in step three in practice a number of standard auto


differentiation libraries like tensor flow and PI torch can handle this quite gracefully and and really you don't have to worry about it too much at all and it also isn't particularly computationally expensive but we will talk a bit more about a ways to mitigate this in a few slides okay so now how does this approach compared to the black box out of potations that we mentioned before so let's bring up the general form that we talked about before where you have some neural network that's taking a training data point or training data set and a


test data point and it's producing a prediction for the test data point it turns out that you can view the optimization based approach in the same general form so before we were using like a recurrent neural network to represent this function but now we're using what I'll denote as F mammal to represent this function and that is the function with parameters Phi that takes an X tests and produces a prediction where Phi is defined as the initial meta parameters plus gradient descent on the data point and so essentially you can


view the mammal algorithm as a computation graph just with this funny embedded gradient operator within it and so I really you can just view it as a very similar approach for doing it but one that has a lot more structure the structure namely of optimization within it and also with this view that means that we can very naturally mix and match components of these different approaches so for example one of the things we could do is learn the initialization that that mammal is doing but also learn learn how to make gradient updates the


initialization and that's exactly what ravi and la rochelle did in 2017 which actually preceded the mammal work and the and this computation graph view will come back again in as we discussed the third type of approach great so questions how is theta G learned this is coming back to the black box adaptation yeah so great question so theta G this is going back to the black box and in that case we had a we had a very like submission statistics age that are produced by the neural network and we also had theta G that was using to use


to make predictions about the test data points and in that case theta G is optimized with all the other meta parameters of F so it's optimized just like all the other meta parameters another question about the black box setup tation so we'll Hib trivial meaning like why wouldn't a chai just learn to recognize which task is fed in and just up what's sort of like a one hot indicator for one of the N tasks that's a good question I think that in practice it doesn't do you have an answer for that yeah maybe one way to


think about this is it's kind of the same problem as memorizing labels for regular supervised learning so in the same way that supervised learning can overfit meta learning can net over fit so if you start seeing that your that your model just outputs a task indicator that can happen if you have a very small number of meta training tasks that's just an instance of overfitting we'll talk about metal or filling towards the end of the tutorial great oh one more another one I don't know if you know this but what's


oh gee from memory augmented neural networks yeah so that's a great question so the memory augmented neural networks question by santoro at all basically that just used a standard RNN to take in data points including the test data point and so in that case theta G was actually the same exact parameters as theta in F so H the sufficient statistic is simply the hidden state of an RNN and there is weight sharing across across theta G and theta enough where it's represented by the the weights that are shared across time and it recurrent


neural network so this one is a crowd favorite apparently how was oldest related to hyper networks where we were interested in giving parameters of a model s output great yeah so the the first blackbox annotation approach is also what is done in hyper networks I think that I'm not completely sure about this but I think that the hyper networks paper wasn't particularly focused on better learning problems and look at you looking at other problems where you're gonna be outputting parameters of neural networks but the approach the algorithm


used is is exactly the same as the black box on updation approaches that I mentioned before this question I can answer myself can we adopt mammal in a framework that we don't have a batch of tasks ahead of them instead we get them sequentially to hear the answer this question you'll have to wait until the very end of the tutorial on the last slide and she'll see we'll answer it okay one quick audience question okay so this is a question about FML so if I understand it correctly that MMO essentially learns the base model which


kind of in the middle of like the optimal parameter for different tasks but it's it is working analyzing an assumption that those optimal parameters for those different tasks are now too far away so if depth in some kind of if you are choosing a model space that the optimal like parameter or far away so that maybe you're the middle point of the base below although it is not too far away from each of the optimal parameter it might be not optimal for any of those I noticed it in the original paper that you are basically using a pretty simple


commercial neural net which have fewer neurons I'm just wondering will the MMO works keeps its performance like if you are using a more complex model where its parameter space is more complex and speaker yeah so first it's mentioning that this diagram we like to use for an illustration purposes in terms of understanding the algorithm but it can also be a bit misleading which is that in many cases particularly with heavily over parametrized neural networks there isn't just a single optimum for the correct solution there's actually an


entire space of optimum and and with with those types of problems we see that the it is actually a little bit easier to find something where you're simply one or a few gradient steps away and in fact in a minute I'll talk about the expressive power of of the Manuel algorithm and its ability to adapt even when your tasks are extremely different with regard to architectures I'll talk a bit about that but in practice we do find that it scales well to to larger larger architectures but it may require a bit more tuning than other meta


learning methods okay thank you okay so great leaving off where you left off so mammal exhibits this kind of structure unlike the black box on updation approaches which is it has this gradient operator inside of it and so it's actually performing an optimization problem both within the better training process as well as it met a test time and so one thing that might be quite natural to ask is using that structure does that mean that we can generalize better to two tasks that are slightly out of distribution and this is of


course an empirical question that we're gonna study more so than a theoretical question and so what we're gonna do is we're going to compare mammal with with blackbox annotation approaches such as snail and meta networks and we looked at image Dominika image classification problem and we tried to plot the task variability versus performance and what we found consistently across the board is as we move away from the the Mediterranean tasks with either zero zero shear or a scale of 1 we see that of course performance drops for all


approaches but that mammal is able to perform better because it has the structure of being able to run in gradient descent at test time and at the very least you are still running grained descent so you'll you won't be doing significantly worse than then what you might be doing with with a neural work that you really don't can't really say anything about if it's just outputting parameters for example okay so you might say well we get this nice structure but does this come at a cost like as the question alluded to before


do the did you need to assume that the task parameters are very close to each other for different tasks and so we studied this question by studying the expressive power of a single gradient step basically the update that's used in the mammal function and what we can say is that actually for sufficiently deep neural network function f the mammal function on the right can represent anything that the recurrent neural network can represent on the Left which is that it can represent any function of the training data and the test input and


we can show this under a few assumptions that are relatively mild such as the non zero learning rate as well as unique data points in the training data set and the reason why this is interesting is that it means that mammal has the inductive bias of optimization of precede procedures being embedded within it but without losing the expressive power of gradient descent or without losing the expressive power of deep recurrent neural networks ok great so let's go back to some of the motivation that we talked about a little bit with


optimization based approaches where we're saying that the meta parameters serve as a prior and we talked about how one form of prior knowledge is is initialization for fine-tuning can we make this a bit more formal and actually better characterize what's work sort of prior that is it mammal is imposing on the learning process and to do so we're going to look at Bayesian meta learning approaches that use graphical models so this is a kind of a graphical model similar to the one that Sergei showed before where Phii is the top specific


parameters and theta is the meta parameters so if you want to do do meta learning or learn a prior theta in this graphical model it's gonna look like the following optimization where we're optimizing the logs likelihood of the data given given the parameters you can write this out similar to the equations that Surya showed earlier as an integration over the top specific parameters Phi which are not observed and the and this is simply empirical Bayes and the we can approximate is is it's quite intractable and so one thing


we could do is we could approximate this integral with you maximum a posteriori estimate of the Taos Pacific parameters Phi I and this is a fairly crude approximation but it but one thing interestingly that we can show is if you compute the map estimate basically gradient descent with early stopping corresponds to map inference under a Gaussian prior with mean theta and a variance that's a function of the number of gradient descent steps and the learning rate and this is exact in the in the linear case and approximate


approximate in the non-linear case and so what we can see is that through this approximate approximate equivalence as well as the appraoch the approximation of the integral with the map estimate is that mammal is approximating inference in this hierarchical bayesian model which i think is useful for providing some intuition for the types of priors that we're learning in the meta learning process okay so mammal is a form of implicit prior are there other forms of priors that we can impose on the optimization procedure one thing we


could do is do grain descent with an explicit Gaussian prior the log likelihood of a Gaussian shown here and this is what was done by Reuters Warren at all in the implicit mammal paper we could also have a prior used in Bayesian linear regression in this case we can't input and post a prior on all weights of the neural network that would be intractable but we can impose it on the last layer of the neural network and do that on top of metal earned features this was done in an alpaca another type of mammal and we can also


this is moving more away from Beijing about this but we can also do other forms of optimization on the last layer of the neural network such as doing Ridge regression logistic regression or support vector machines and this is uh this forward prior is essentially that we want features that are useful for linear classification that can be performed with these methods and to my knowledge is this last approach meta objet as the current state of the art on P shot image recognition benchmarks okay so now that we've talked about


optimization based approaches let's go through a couple challenges with them so one challenge is how do you choose an architecture that's effective for embedding this integrated in descent procedure and one way to do this is to do architecture search and the interesting things that was found in this paper is it found that highly non-standard architectures that were very very deep and very narrow we're quite effective for use with mammal and this is a bit different from standard architectures that work well for


standard supervised learning problems and I'm particularly many images at five wave five shot classification proceed benchmark mammal with the basic architecture I see achieves around sixty three percent accuracy while mammal with the architecture search is able to achieve seventy four percent accuracy a pretty substantial boost by actually tuning the architecture that works well for it lastly one other challenge that you come up with with the medal the mammal algorithm is that you run into the second order optimization procedure and


this can exhibit different and different instabilities one idea for trying to mitigate this is really the dumbest idea you can come up with is to assume that the Jacobian of Phi with respect to theta is identity and simply copy the gradient with this rectify to be the gradient with respect to theta and this actually works somewhat surprisingly well oddly enough on relatively simple problems although anecdotally we found it not to work well as you try to move towards more complex problems like imitation learning and reinforcement


learning I another thing you can do is automatically learn the inner and outer learning rates you can also optimize only a subset of parameters in the inner loop such as the last layer or affine transformations at each layer you could also try to decouple the the learning rate in the back term statistics that each gradient step to have fewer decoupled parameters that might cause instabilities and finally you could also introduced introduced additional context variables into the architecture to allow for multiplicative interactions between


parameters and allow for a more expressive gradient and so come my takeaway here is that there are a range of simple tricks that can help the optimization significantly great so before we move on to nonparametric methods let's take one question from the audience and potentially some subtitle questions do you know how Mammon compares to other first-order method learning algorithms particularly reptile by Jones shown many tail so you questions how does it compare to first-order algorithms like I mean can it get over some of these problems


you just presented in this fight and you're asking about the de mammal no like if you see reptile which is a first-order method for meta learning instead of mammal can it get over some of the second-order gradient problems you just presented here yeah so as I mentioned on the on the first idea I listed here both first-order mammal and reptile do by using this crude approximation you can have a faster optimization procedure and and it potentially can be less stable but the the main benefit that you get from it is


this is faster and lower in memory but we have found that there are a number of problems where these types of first-order methods don't work at all and you need to use the the second-order methods in order to optimization optimize them well thank you why is theta minus Phi in the Gaussian prior this is a few slides ago the answer to this question though is that the the interpretation as a Gaussian prior it basically says that the prior is on Phi and Phi is normally distributed with a mean of theta the variance of that prior depends on the


number of breeding steps you take which is actually a very natural thing bei so the more grading steps you take the further away you get from theta that corresponds to a prior with the wider variance next question is there any guarantee or test that Phi is not multimodal as map will assume unimodality yeah so it's certainly yeah this this tribution certainly could be multimodal and this approximation is ignoring that in practice we have found that that mammal can work quite well on multi modal problems where you have like


quietly quite different functions that you're that are represented in the task variables although you do need a deeper neural network for that and there are also approaches such as multi modal mammal I believe that try to tackle this problem head-on and enable you to get more efficient use of your neural network parameters and by by allowing it to represent multimodal distributions over five data a couple more quick ones in the case of orthogonal tasks with mammal just memorize so if the tasks are if a single function can represent both tasks


without relying on the data then it will just memorize the function and ignore the data in many cases can we do gradient descent for multiple steps to get Phi in mammal yeah absolutely so you can use a variable number of gradient steps and practice we found that up to five gradients that works well but in practice you can use you can use more than that if if you find it helpful for your algorithm I it does not introduce higher order terms than a second order optimization it still remains the second order optimization if you go through if


you go through the mouth okay great so let's move on to nonparametric approaches and so far we've talked about parametric methods and that we're gonna be learning a model that's parameterize by five and and what about using methods that don't have parameters five and the motivation here is that in low danger regimes nonparametric methods are quite simple and work quite well and during meta test time we're in a future learning setting and so we are in elite low data regime however during but a training we still want to be parametric


because we have large amounts of data across all of the meta training tasks so the key idea behind these approaches is can we use a parametric meta learner in order to produce a nonparametric learner okay and note that some of these methods that I'll be presenting do precede parametric approaches but we're presenting them in this in this group setting to aid in understanding okay so the key idea here is is here's a few shell learning problem and one of the things you might ask is well what one thing you could once very simple thing


you could do in this approach is just take your test data point and compare it to each of the the data points in your training data basically do nearest neighbors by by comparing to each of the images the this is a quite a simple opportunity quite valid for these types of problems the key question is in what space do you compare these images and with what distance metric I for example you could do pixel space or l2 distance but that probably wouldn't give you an effective metric over the similarity between these


images and so the key idea behind these on parametric methods is to learn a metric space that leads to effective comparisons learn a more semantic metric space that leads to effective predictions on the test data points and then we learn how to compare these images to make effective predictions and so the first very simple approach for doing this is to train a Siamese Network to predict whether or not two images are the same so we can train a neural network that takes in two images and is trained to output whether or not they're


the same we're not so zero correspond so them not being the same one corresponds to them being the same class and repeat this through all of the data in your meta training data set and so once you've trained this neural network to be able to compare pairs of images about a test time you can then take your test data point compare it to each of the images in your training dataset see and then output the corresponding label to the image that is the closest okay so in this case meta training is give me a two-way classification problem and then


meta testing is going to be an anyway classification problem by doing all of these pairwise comparisons so now to improve upon this approach you might ask well can we make Mediterranean meta testing match can we train it such as it can actually perform effective anyway classification and this was kind of a key idea that Sergey alluded to in the problem definition which is to try to match Mediterranean meta testing in this case putting a an NBA classification problem with nearest neighbors into a neural network and so we're gonna be


feeding the train data set as shown on the left into an into the neural network comparing this to our test input shown on the bottom two and outputting these similarities and then training it such that the predictions that it gets out which corresponds to weighted nearest neighbors are correct with respect to each of the tasks in our meta training set cool so this is basically embedding nearest neighbors into a neural network the the metric that we're using can be correspond to a convolutional encoder or some other architecture to get the


embeddings of the training data points this method uses a bi-directional ostium and then we get a model that can do anyway classification is actually better trained for anyway classification now if you have more than one example per class what this will do is it will independently compare the test image with each of those examples per class and one of the things that might be nice to do is actually to better integrate the information across different examples for our class to aggregate cost information into a sort of prototypical


embedding of that class such that when we do comparisons we're comparing at a class level rather than at the example level and this is exactly what prototypical networks does so they embed each of the data points for a given class such as the class corresponding to green blue or orange I average these to compute a prototype shown as CK and then make predictions based off of embedding the test data point X test and comparing it to each of the prototypes and what this looks like is we simply measure the distance acts between each of the


prototypes this is denoted as D and then perform a softmax operation to decide which class it corresponds to and in this case D can correspond to Euclidean distance or cosine distance great so this is a simple approach that works quite well and there are a couple other extensions that we can make upon it so so far we've looked at Siamese networks about two networks they're prototypical that works at all correspond to some sort of embedding in the nearest neighbors either two examples or two prototypes when tanta comes up is what if you need


a reason about more complex relationships between data points we don't simply want to average to create a single prototypical example pour per per class to handle this we could learn a nonlinear relation module on the embeddings so we can essentially learn that D function by embedding each of the pairwise examples and and producing predictions for each of them we could also learn a different prototype more than one type for each class learning an infinite mixture of prototypes or perform message passing on the different classes and the


different examples in our data set okay so stepping up a bit let's actually try to think about how these different approaches compare so you can go back to the computation graph perspective and bring up the kind of computation graph view of the black box approaches as well as the optimization based approaches and the nonparametric approach can be viewed in the same exact way except here I we're gonna be having a new function which I'll denote as PN for prototypical networks where the function corresponds to the softmax of the the


negative distance between the embedded query tests data point and the prototypes where the prototypes are defined as the average embedding of each of the class for that example and so with this view again we can mix and match components of this computation graph to create hybrid approaches among these different three and this includes things like camel which can both conditions on the data with a black box approach and run gradients and runs grain to send all the parameters it's also another hybrid approach is to run


gradient descent on an embedding that produces a set of parameters so this sort of combines all three approaches and then finally we can do something like mammal but initialize the last layer to be a linear classifier equivalent to the prototypical networks classifier okay before we move on to the takeaways are there any questions about nonparametric approaches or any questions from slide oh no there are roughly 200 questions and I can't sort through them all but there are a couple of questions that are kind


of crowd favorites that are maybe good to take not not to do that primary methods necessarily but one common theme is well can we do meta training where we have different numbers of classes for different tasks or different numbers of data points for different classes yeah absolutely so and actually this is a this is a good question to talk about now too because um these different approaches can handle variable numbers of training data points and numbers of number of data points per class and varied number variable numbers


of classes the this is something that optimization based approaches can handle very gracefully because you can simply compete your loss function over different batches of data points very very naturally blackbox approaches you can do it but you need to train it for to be able to do that you need to be able to train it with variable data set sizes and variable numbers of examples per class and nonparametric approaches can also handle it fairly gracefully but in practice we found them not to always work well to to variable numbers of data


points per class so another question which is kind of a summary of multiple questions but I think it applies to all three of the methods as well to what degree to meta learning methods actually learn to use the entirety of kind of a test batch meaning that they classify multiple images at once versus are they classifying individual images one at a time this is all the questions about inductive versus transductive are also getting at this point yes I think it depends on your application so if you think that you are going to have just a


single example that you need to classify it test time then then all of these approaches can handle that setting and then if you're in the transductive setting and you think that you're gonna actually have a test dataset that you need a label that corresponds to two multiple classes then you could also you could either independently classify them of course or try to actually combine information between them different approaches can handle this in different ways for example you can use the batch storm statistics to I basically transmit


information across different tasks or across different examples in your meta test set and with this you can actually transmit a fair amount of information through those about statistics and there are also more recent approaches that try to learn lost functions that can effectively transmit information across unlabeled examples another common theme in regard to mammal and a few questions here is well what are the relative benefits of simply doing pre training followed by fine-tuning versus doing a mammal and also can mammal itself be used as just a


pre training stage without any fine-tuning so in practice mammal is certainly training for like fine-tuned ability to a new task and so I'm practice you really do need to actually fine-tune it to a test task although perhaps if you only care about getting good features and maybe the features learned by the method are something that is reasonable okay so some intermediate takeaways of these different approaches one of the benefits of things like blackbox approaches is that they are easy to combine with a variety of


learning problems such as supervised learning and as you'll see after the break and reinforcement learning they do involve a challenging optimization problem and this is a bit of a subtle point which is that initialization because you're not embedding a known learning procedure into the meta learning process there's no inductive bias that points you in the right direction for how to learn from the data and as a result you have to learn how to learn from the data completely from scratch and as a result these methods can often be data


inefficient because that optimization process requires time to actually learn how to learn from data and lastly these methods do have an intertwined model and architecture essentially the the model that you're using to make predictions about data points is inherently intertwined with the model that you're using to to take in the training data points as input okay as I mentioned before optimization based approaches can very nicely handle varying K and large K the structure also lends well to out of distribution tasks and one of the


downsides is that does it involve the second order optimization although there are a couple of approaches towards trying to mitigate this nonparametric pressures are quite simple and they're entirely feed-forward and because they're entirely feed-forward they're computationally fast and easy to optimize because you don't need to worry about by propagating through gradient steps or through recurrent neural networks for example they're harder to generalize to varying K this is more of an empirical observation than


then a theoretical one and of course because they're using non parametric approaches they're harder to scale to very large K because the the computation grows with more and more data points okay and the mostly to the approaches so far have been limited to classification approaches because you're inherently making making decisions based off of the based on the data points that you've seen so far okay and lastly it's worth pointing out that well tune versions of each of these approaches tend to perform compare ibly on existing few shot


learning benchmarks so at the performance level they all perform quite well okay so now let's talk about Bayesian meta learning approaches so we had this really nice motivation for for Bayesian methods and then we kind of threw that all away in the last thirty minutes or so and so and particularly what we did is we assume that this PFI given the data set and the meta parameters is going to be a point estimate or a deterministic function of the training data point and and the meta parameters you might as well maybe this


is all fine like we don't we don't really need Bayesian things but there are many situations where it actually is useful to be representing actually a distribution over the potential functions that we might be encountering and in particular because future learning problems only have a small number of data points they may be ambiguous even with when you do have a prior for example if your goal is to classify between all the images on the left and all the images on the right all the folks on the left are smiling


wearing hats and young all the folks on the right or not and so if you get an image that has someone that smiling and wearing hot and not young or not smiling and wearing a hat and young that it's inherently ambiguous on what the correct label is for these classes because you don't know if you're supposed to classifying on the attribute of smiling on the attribute of wearing a hat or on the attribute of being young and so what you might ask this can me generate hypotheses about the underlying function I like the three hypotheses that I


mentioned before essentially can you sample from this function PFI and this is gonna be important for for ambiguous problems but also for safety critical few shot learning such as medical imaging for learning to actively learn because if you care about actually reducing your uncertainty about a given function and getting labels for new data points and you want to be able to reason about your uncertainty over your function space right now and it's also and there have been approaches for using active learning with meta learning and it's


also useful for learning to explore and meta reinforcement learning because again we can try to explicitly reduce our uncertainty by collecting more data okay so how do we go about trying to medal learn in a way that allows us to generate hypotheses and reason about distributions so we can bring up the graphical model that sorry I mentioned before where we're going to have a distribution of our prior parameters theta we will have a distribution over our TAS specific parameters by I given theta and then we'll also have


probability distributions correspondent the probability of our training dataset giving or given our toss parameters and our test dataset given our task parameters and then our goal will be can we sample task specific parameters Phi I given our training data points and ex-house essentially given all of the observed variables and because of conditional independence a test time we we don't really need to worry too much about X test we just want to be able to sample Phi I given x training in a white rain so blackbox adaptation approaches


are quite easy to to extend to this Bayesian setting so what we can do is we can use amortized variational inference we can train a neural network to represent a distribution over sufficient statistics we can also represent a distribution over full parameter vectors Phi I although that might get a bit unwieldy at some point and so we could train a neural network to represent a Gaussian distribution over H and then feed this H into another neural network and use ideas from from amortized variational inference such as the


reprioritization trick to train this model in order to effectively produce this distribution indeed various approaches have used this type of approach for example Gordon at all I use this approach where H correspond to the the weights of the last layer of a neural network okay so now now that we've gone over how you can a very naturally apply this with blackbox approaches what about optimization based metal learning approaches can we further extend these to the Bayesian setting there's a few different ways that you go


about doing this well this is this figure than the simple black box approach one thing we could do is model the distribution of Phi given theta as Gaussian and use the same sort of variational inference for training as I mentioned before but have her inference that work you perform an optimization over Phi and this is what was done in Ravi and pizza in 2019 another thing that we want to do is if you don't want to model p5 theta I give PFI given theta as Gaussian we can use stein variational gradient to on the last layer of the


neural network and do gradient based inference on the last layer and only have a single set of parameters similar to theta G for all the other layers and also we could use something like an ensemble of mammals ensemble of méditerranée all networks that allows us to represent basically particles of the distribution and both of these were proposed by Kim at all in 2018 know one thing you might ask is well can we can we get some kind of the benefits of both of these can we model both a non Gaussian posterior and do so over all of


the parameters and there is a way that we can do this in fact and so let's go back to our graphical model say that we want to sample from this this distribution you can write out as the integral where we're integrating out p theta of course this integral is completely intractable if theta are the parameters of a neural network but one thing you might ask is well what if we knew p if i given theta and the training data set if we knew this distribution our graphical model would be transformed in this way switching the arrows from


the training dataset to 5 and then we could simply sample with ancestral sampling we could sample at theta from the prior sample 5 from this distribution and and and get get a get a sampled 5 and so the key idea is what we can do here is we can approximate this distribution Phi given theta and D train as a a point estimate using map of course this is extremely crude approximation similar to the one that we use in mammal but it's also extremely convenient and in particular if we do this approximation we can still get


samples from PFI given the training data and in fact we can to do this approximation we can use the same gradient based map approximation as shown before but we don't require we don't require doing the intractable integral at the top okay so at test time what this corresponds to is we'll have initial set of parameters theta will add noise to sample will add noise so that that parameter vector to basically sample a new theta and then we will run gradient descent from there so it's essentially a way to make mammal


they give you estimates and sample from PFI given your training data but I'm doing so in a way that actually will lead to the correct posterior distribution I didn't go through actually how we train this that's a bit harder and for details you can look at the probabilistic mammal paper on the bottom we refer to this algorithm as platypus or a probabilistic latent model for incorporating priors and uncertainty in future learning which is a bit of a tortured acronym but we can then get another type of male and what this gives


us is it gives us the ability to sample different functions with only a few data points such as linear functions sinusoid functions but they were inherently ambiguous because there's some noise in the data as well as represent different classification problems for different classifiers with different decision boundaries as again shown in the colored dashed lines and perhaps most importantly it's also it's better able to model ambiguous future learning problems like I showed on the first slide okay for further reading on


Bayesian by learning approaches you can look at the papers shown here and next we can go to a couple questions before moving on to applications so one question is if we want to do a Bayesian metal learning approach can we just use drop out at a test time right so if you just do drop out at test time you will certainly get a distribution there's no guarantee if you don't train for that distribution to actually represent the posterior then you won't actually get the correct posterior over functions for probabilistic mammal


you assume that there's no relationship between the training X and the training Y the graphical model assumes that the that there is that the labels Y are dependent on the inputs the the labels Y train are dependent on the inputs X train and the the parameter is Phi okay so let's go through a couple applications this will be quite quick meta learning has been used in a variety of computer vision applications such as image recognition modeling the motion and the pose of humans uses for domain adaptation for example when


you want to adapt to new domains and you have a variety of domains to train on as well as for a few shots segmentation problems or you want to segment images given only a few labeled pixels beyond some of those kind of typical supervised computer vision problems people have also looked at tired of modeling with with meta learning methods this includes a few shot image generation if you shot image the image translation when you where you want to translate between different types of images where you want to translate things to a new type of


animal that that you haven't seen before also generation of novel viewpoints given a single viewpoint as well as generating videos of people from just a single image of that person okay and then another application that people have looked at is imitation learning where the goal is given one demonstration of a task can you learn a policy for that task and this is quite a fairly simple extension of the supervised meta learning approaches that we showed before because you can treat imitation learning as a supervised


learning problem this has been looked at for stocking blocks on top of each other for extended step temporarily extended tasks also for other kind of robotics control tasks in the real world as well as for high fidelity imitation where you want to very closely match the the training demonstration and also it has also been used with optimization based patient techniques such as it showed here so here the goal is to after seeing a single demonstration of placing an apple into a bowl through teleoperation throughout what is able to figure out


how to place the Apple onto the ball in new situations in this case I the the robot had never seen any of these objects before and so it's adapting to being able to manipulate objects in new objects in in this setting okay and also for more advanced topics you can look at approaches for one time inverse reinforcement learning and one-shot hierarchical imitation learning now one thing you might say is can we take this one step further can we do imitation from a video of a human per se where our goal is given a video of a human


performing a task such as placing into the red bowl can the robot figure out a policy for placing for performing the toss turn in the video such as placing the peach into the red bowl and in this case you need to learn how to learn from weak supervision and what I mean my weak supervision is that the video of the human has all the information about the task but is not accessible in a way of kind of a standard machine learning data set and so we need to do something a bit different here and in particular what


we're going to do is we can take the the mammal objective or really any meta learning objective and the the the meta objective the outer objective is going to be fully supervised and the inner objective is going to be weekly supervised so we're be learning how to learn from weekly supervised data using fully supervised data and then a test time you'll run gradient descent using the weekly supervised data now you one question you might ask is well what if the weekly supervised loss function isn't available like from a video of a


human in that case you could actually learn a loss function for performing adaptation such as I know all Network loss function that outputs a scalar value and you train this loss function such that the gradients it provides are effective for adaptation okay and then lastly it's worth mentioning that meta learning for languages been explored in a variety of contexts this includes adapting link adapting models to modeling new programs such as program induction and program synthesis this also includes adapting to new languages


such as translating between two language pairs that you only have a small amount of data for by meditating on language pairs that you have a lot of data for this also includes learning new words so this is actually done in the original matching networks paper that learns how to use a new word in the new context from a single example usage of that word and lastly adapting to new personas so training dialog agents to be able to generate dialogue from a particular persona from only a few examples of that persona okay


[Music] so hi everyone uh i am glad to have to have a chance to give this talk to you today uh so as dragon already mentioned uh the title is api design uh tips and uh introduction into building the apis uh so thinking about this topic uh uh it's in this talk it's it will not be a matter of uh talking about one correct approach uh as uh there are many good ones uh the goal is stop is to talk about the ideas and thought process and how you can use those when designing and thinking about uh apis uh the talk will not cover

API Design - Getting Started—Alen Pokos


the whole topic because uh this is a very very big area to talk about uh so i will uh focus on some of the selected areas that i found in my experience to be the most available when thinking about the api design examples shown in this stock are inspired by real life uh some of which are simplified or adjusted to fit the format of this talk first let me let me introduce myself to you as dragon already mentioned my name is allen i'm a deputy cto and team leader of architecture team at decoder i've been building web apps and apis for

API Design - Getting Started—Alen Pokos


a very long time now i've been building json api powered projects for the past five years i'm doing talks training workshops and educations as part of my daily work let me talk about a little bit about our company so three coder is a company based in zagreb croatia and we employ uh developers uh uh on premise and remote also from uh some uh neighboring countries uh we are medium company with 65 employees out of which 50 are developers and engineers so we cover mobile front and back and data science ux and ui

API Design - Getting Started—Alen Pokos


uh our main project is uh nuscolo it's a classified platform which is number one in oh sorry do you see it now ah okay yeah sorry there was a miss in the shires uh okay uh so we have a uh our main project is a new scholar uh it's number one uh platform in croatia and uh also in slovenia and we are always open to hire uh new colleagues so feel free to check out our website for more information uh on to the topic so uh when we talk about the apis uh uh depending on your technical background uh the api can uh mean several different

API Design - Getting Started—Alen Pokos


things so let's try to clear up uh this definition first so uh in our definition apis uh is something that enables application to communicate with one another uh this can be either uh server to server a client application or some other service that you are building so a well designed api should reflect the goals of business and it's designed to serve that purpose the idea here where will talk about is uh web apis but the ideas and thoughts are also applicable to other areas as well uh so when talk about uh talking about

API Design - Getting Started—Alen Pokos


the web apis we need to mention uh restful apis uh so it's an architectural style for uh building distributed systems based on hyper media and it's not necessarily just implying uh http uh so web apis is what we will talk about today a couple of things to mention here uh web is usually a stateless request model using http and the http requests should be independent of each other and may occur in any order uh this is something when uh thinking about the how we will model our uh endpoints so uh why we use apis uh so apis are

API Design - Getting Started—Alen Pokos


used to build uh webs to build for other web servers or client consumers such as web browser mobile application uh outside services uh one thing that we can also uh usually imply its communication is done using http protocol in some text formats most preferably json or xml so before we dive into the apis we can also talk about the design world design world itself can have several meanings and one definition that i found very useful is design is a set of decisions with the goal to define the look and functionality of

API Design - Getting Started—Alen Pokos


the topic that you are designing uh so it's a simple but valuable definition that can help us understand when we talk about the design so uh what does this mean in a sense of api design so uh api design is a process of developing uh interfaces for exposing our functionality or data to other applications as such a good api design takes into consideration organization specific strengths uh and uh limitations in terms of budgets personal skills and technical uh infrastructure so i said here we need to think about

API Design - Getting Started—Alen Pokos


also the technical approach but also take into account the consumers and our business that we are trying to support here uh one thing that we uh often uh come into across in our experience when talking about the api design is uh when people disagree on design it's often they don't agree on the goals and in my experience this is one of the very important notes to have in your head so because a lot of times the discussions is about the design but we need to consider uh what what is our goal uh so for example if there is a

API Design - Getting Started—Alen Pokos


disagreement that the current design is not future proof for the next five to ten years uh but our goal is to deliver some short-lived feature then this discussion is not needed because it's not our goal we are delivering something that has a shelf life and uh very often in our uh in our area of work uh our solutions have a shelf life because we are always thinking about how to upgrade them so when talking about the design a good design can be broken down into three main aspects those are purpose usability and constraints

API Design - Getting Started—Alen Pokos


uh so a purpose part uh as we mentioned in the previous slides uh is about fulfilling the business goals about getting the right information uh to the right side uh usability and constraints this again can be also covered depending on your technology stack and standards you could already have this covered with some standard that you use so for example in recorder we use a json api standard which i'll mention later in the talk and also give some examples and this helped us a lot to really think about the important stuff

API Design - Getting Started—Alen Pokos


and not to worry about conventions and similar so to summarize what is the api responsibilities it's to provide the data and functionality to successfully complete a business goal uh that business goal can be a sale a conversion a technology related data exchange anything that you are trying to cover one also uh interesting uh thought to have is i think everyone here some variation of this is uh good solutions have strong foundations uh so when thinking about the api design uh there is a way that i can actually

API Design - Getting Started—Alen Pokos


try to visualize this so looking at our solution we built a solution to fulfill some requirements and to meet those requirements there can usually be three main pillars for building the solution so one is a client pillar one is a api pillar and one is a backend pillar again we are talking about the web concept here uh so when each of these pillars are strong we are happy and prosperous and the success is when all of them all the three pillars are working towards a common goal instead of working towards the goal of

API Design - Getting Started—Alen Pokos


one pillar uh so looking at the example for uh in the relationship between the client and the api uh there might be a case where our client needs uh the whole home page for its app in one request and this is something that usually in the api we don't think about like this or for example we have an article and the article has an image so depending on the client we can do it either sending a url or we can have some complex resources additional logic behind it looking at the api and the backend relationship this is

API Design - Getting Started—Alen Pokos


where usually things get a bit more complex in and it involves a lot of more work so sometimes an api can copy copy uh backend implementation one to one so we have the same data models we have the same attributes uh and this can be a good start um but often uh because if we already know the backend implementation we can be biased towards the design of our api and this is uh this can sometimes limit our solution space so if we approach the api design isolated from the back end so not thinking about how the backend is

API Design - Getting Started—Alen Pokos


implemented we can sometimes come up with a really great designs that work uh well uh so for example if in your backend system you have a document revision system but on the api you only need to serve the latest version of the document there might actually be no need to show all this revision system in your apis so when looking at these three pillars if the pillars are too affected by each other our construction can become fragile and unbalanced uh we can become coupled to the dynamic of these solutions uh so for example if our client is doing

API Design - Getting Started—Alen Pokos


uh ui redesign and we need to change uh modify the apis because of it despite the data set being the same this can be an indicator that we are too coupled to the client or if a back end is doing some uh refactoring or optimizations and it requires us to change our api again we are too coupled uh with uh with the back end again as this is the talk about the api so i will focus now more about the api itself uh so uh when thinking about the apis one thing that we can also try to test is okay how will it serve multiple clients does it need to

API Design - Getting Started—Alen Pokos


serve multiple clients uh will it be served to multiple back ends uh how will the filtering down how would the format done so there can be a lot of questions raised what we try to do is simplify and focus on the content instead of form so we should focus on what what kind of data what the data api provides and not how uh when we talk about how uh we usually think about the formats the structures uh and communication uh so this should not be our primary focus so imagine a world where everyone knows what your apis work uh how your apis

API Design - Getting Started—Alen Pokos


work and you just need to tell them what kind of data you are uh serving from it so as i mentioned before in recorder we use json api to help us with this uh what json api provides is uh enables us to stop worrying about the structure and covers a lot of frequent questions that we might find uh so uh json api removes for us the needs to invent things uh that we don't need to reinvent uh the json api itself is a resource oriented api uh they do have a uh really well well written uh specification so i would suggest uh if you're interested

API Design - Getting Started—Alen Pokos


to take a look at it and i'll go over a quick overview of uh basic features of the json api so uh looking at it so this is a basic structure or resource uh it combined it constrained it is comprised of the type so usually some kind of type describing the resource the id of the resource and some attributes uh like a real world example let's see an article so we would have an article uh with an id1 and a title and the body of the article and uh so when we think about okay so i have an article i might need to uh see an author of the

API Design - Getting Started—Alen Pokos


article so this is done using the relationships so we can define a relationship and say okay relationship to this article is an author with a type of people so it gets pretty easy again thinking about okay i know the id of the user it would be great if i have this user included uh in my resource so again i can just simply have it included uh in the main response so again this is the response from from the main endpoint if we need a relationship of a relationship yes the related resources are also resources so we can

API Design - Getting Started—Alen Pokos


have a relationship and again using included we can include the relationship of that uh we can include the resource of that relationship as well so we can get the article the author and the thumbnail used uh to show this out um it looks beautiful uh so to summarize what what the json api provides us that we don't need to think about so it provides us with client responsibilities it provides us a definition of service server responsibilities it defines a document structure uh it provides a fetching of resources and

API Design - Getting Started—Alen Pokos


relationships and it provides a sparse field set so we can just have a selected set of data instead of the complete resources in addition it also provides us a definition how how sorting can be done pagination filtering uh it provides a full crowd operation so it describes how we can create resources updated uh uh updaters relationships delete the resources uh and it also provides a standardized uh errors uh so again it's a it's a nicely written specification uh if you're not familiar with it feel free to check it out

API Design - Getting Started—Alen Pokos


so now that we covered uh some of the definition and some of the thought process uh we can dive into the example because there is a lot of good things to go over uh so first example first use case we have here is a user illustration i think that everyone has once in their life of development uh met with some kind of huge registration so let's look at our uh requirements so we have a requirement that says that we have a mobile app mobile and web apps so we have two clients uh that have two-step registration in step

API Design - Getting Started—Alen Pokos


one the user enters his username email and password and in the step two it enters additional personal information like uh name surname or a phone number so uh when we think about the api design how would we solve this uh well there's actually a trick about it we don't so uh we ask the clients hey this is not our problem uh so from the api design perspective we enabled it uh what this means so uh we separate the work so client is responsible for covering the steps and the api needs to provide a way to validate

API Design - Getting Started—Alen Pokos


and complete the registration process so we would serve an endpoint to validate or verify the user enter data and we would uh serve an endpoint for uh process of registration itself if we look at the resource how would our resource look like so we would have a resource of the type user again this is just the name we can call it user we can call it uh a guest a person a buyer depending on your uh business uh business language and we would have some attributes uh for example username password uh first name and last name

API Design - Getting Started—Alen Pokos


uh so if you've ever done a registration uh there is another example we can mention here uh usually when you ask for the password you also it's a good practice to have a repeated password just in case the user misses or types it wrong so again this is something that we shouldn't do on the uh api level it should be done by the client itself so the client can verify that two passwords are the same and just send us the password again if we want to think about it differently we can probably define the registration

API Design - Getting Started—Alen Pokos


as a process of sending a registration request to create the user and then we can model our uh resource as such so we could have a resource that is type uh registration request with the same attribute so we would have uh username password uh last firstnamelastname and then when we think about it okay so i send a request for registration and when i get a success response uh we can have the created user as in relationship so we can have additional relationship which is a user of type user so for any fans of the rpcs this is one

API Design - Getting Started—Alen Pokos


option how you can do it when you use json api what endpoints should we provide so we need an endpoint for uh creating of the user so for a resource and we provide additional endpoint for validation uh validation and can have a response okay if the validation is correct or a conflict or some kind of custom error and if we look at the other example for registration it could be a similar so we send have a registration endpoint and registration validate endpoint okay next next use case is classified so to help with anyone who is not

API Design - Getting Started—Alen Pokos


familiar with the term classified is a business for uh selling of uh online uh like for example an ebay uh in our case we work for a creation a platform called new scholar the items that you're selling are usually called a posting or a listing sometimes ad and this use case will be example of uh evolution of the design as we get more knowledge additional requirements and to get more familiar with the topic that we are covering so uh first requirement is we need to serve the list of uh posted listings uh sounds simple enough so we would

API Design - Getting Started—Alen Pokos


create a resource called listing and our listing would have a basic attributes of title description price and when it expires and it's a simple resource we can have a list of them and just serve the all the listings in the database but then we get additional requirement that says hey can you please please include uh seller information like his name and his contact information so uh again a simple so simple approach would be we just modified the existing listing uh with the title description pricing expires on and we add a seller name

API Design - Getting Started—Alen Pokos


and a seller contact phone it's a simple addition uh but this is where the design thought process starts to think so uh the seller data can also be separated into additional uh additional resources and it can be reused on other endpoints so we could do it as additional resource so we would have again our listing with existing attributes and we would have a relationship to a call seller to a special type of resource and let's look at some examples so first example would be we can have a research type seller and then we can

API Design - Getting Started—Alen Pokos


have an attribute called display name and content form it's it's a pretty simple one uh we can be a bit more uh descriptive so again we could have a seller but we could also signify that the seller is actually a user so we would have a relationship to some existing user and in this case our consumers can get even more data about it but looking at this example we can also uh think about the third example is that relation to the seller is a user so we can just have a resource user and we can have his username and phone uh directly attached

API Design - Getting Started—Alen Pokos


uh with this example then we get a new uh requirement which says a mobile application needs to mark ads that are owned by currently logged in user uh and expand an additional data so thinking about this request how how can we uh solve it so if you remember the previous slide it sounds like a ui thing right well correct we could enable this so uh we provide the mobile application with the example to get the current logged in user and then the mobile app can have a simple logic as hey if the classified seller id is the

API Design - Getting Started—Alen Pokos


same as the login user this is the logged in user so no additional data is needed for uh for the api and this is one example where we could become coupled to the ui but again if we think about design if we think about the requirements define them correctly define the goal we can already see that this solution exists in our system let's look at another use case so uh there is a requirement that says okay i as a user need to see my items so we need to enable a seller to see all of the listings that uh he has he's the author of uh so there are a

API Design - Getting Started—Alen Pokos


couple of ways we can do this so one way uh look in the json api uh perspective we could filter the classifieds list and say okay filter classified list where seller is x and the x can be an id of the logged in user again this is all up to the clients to figure out the logged in user another example can be that we can add a special identifier called me and in that case depending on the context of the request uh we can see okay who is the user authenticated with this request oh we can then filter it uh for the client uh this is a bit

API Design - Getting Started—Alen Pokos


more friendly to the clients but again it might be a bit more coupled to the to the client and to the back end uh pillars another way we can also create a special uh endpoint like classified me or uh we can also uh create uh in the users on the user relation to the classified so that the user can filter all of the classifieds that are related to his user uh so again to notify here that uh me keyword is a special in this case and this is again very very specific to the implementation and a bit more coupled to the to the back

API Design - Getting Started—Alen Pokos


end so this is something to take into with caution uh another use case let's look at the messaging so we have a simple uh functionality where a couple of uh users for this example a seller and buyer can have a conversation on the item or listing so looking at the resource we could have a resource type conversation uh and we have participants so we can have the attributes of when the uh conversation is created and then we can have a relationship to a uh classified so this is the item that we are discussing about uh the buyer

API Design - Getting Started—Alen Pokos


and the seller so the the two users that are uh currently participants of this conversation so looking at this conversation can have also additional attributes but we could already maybe uh simplify this so we can have a conversation that has a seller and a buyer and both of them are specified the specific research types so we can sell it with the type seller buyer with the type buyer but also we can reuse them because looking at both of these user types they can be type of user so we reduce the number of special

API Design - Getting Started—Alen Pokos


resources that we have another example another design choice that we can do here looking at the conversation example is that we can have a classified so we have a item that they're discussing and we also have a seller but we already know the seller from the classified so we can uh say that uh seller is uh redundant because we can just say hey give me the seller of the class right so again design choice that we can simplify the endpoint by complicating the job for the client it's a design choice in this case it's

API Design - Getting Started—Alen Pokos


really hard to say which one of the two is better now that we have a conversation we also need to have some conversation messages uh again here is some we can have a resource type message and then we can have a design choice do we group the messages into conversations or we connect them directly to the participants so for example we would have a message that has a content it has a sent on and it has uh is read it's always read by the recipient uh and then we can have a relationship that says okay it's part of the conversation x it

API Design - Getting Started—Alen Pokos


has a sender and it has a recipient looking at this maybe we can find uh some redundancies because in the conversation we only need the sender and the recipient is the other party in the conversation so we can probably uh move this and also when we think about sender and the recipient types we can look at some options so we have a sender who can be a resource type sender and we can have a recipient who is a resource type recipient thinking about the previous example they are both message participants so maybe we can have

API Design - Getting Started—Alen Pokos


a reused resource type that has okay this is a conversation participants and we can reuse them another thing so we can also remove the recipient because we already know that recipients are all the participants in the conversation so again we can simplify our message resource and look at the conversation resource for uh more information uh talking about the resource types so too many resource types can become a problem uh it can be a maintenance problem it can be a design problem because uh you start to maybe get the track

API Design - Getting Started—Alen Pokos


lose the track of which resources uh are uh intended for what so for example we can have a user we can have a buyer we can have a seller then we can send a recipient uh customer uh etc so if you look at all of these resources they can all uh be basically come down to a simple user or a customer or some other solution that works for you so again thank you to account it's it's nice to have a really specific uh resources but when you build your apis it can become overwhelming and it can become a maintenance nightmare

API Design - Getting Started—Alen Pokos


uh another use case that we can look about is a search so we have a simple request we have one search endpoint for several resource types so we can uh so let's look at the one solution how we can build our search uh functionality so we have a resource type that search result and then it can have an attribute of title and some excerpt so we can show the matching keywords and relationships is where it gets interesting so let's say we have three main resource types that can be in our search results so we can have a

API Design - Getting Started—Alen Pokos


classified you can have article and we have category uh as uh the definition of json api says that you should only serve one resource type with endpoint so we need to have a search result and then using a relationship we can say okay this is a classified this is an article and this is a category and then within the included we can have the complete document uh another alternative for this uh can also be we can reuse a relationship so we can have an attribute with uh title and excerpt and then we can have just one relationship

API Design - Getting Started—Alen Pokos


which is called the result and depending on the type of the related uh resource we could know that it's a classified it's an article uh or it's a category so this is another example of how we can do this there are many more examples that i could be showing but given that we cannot be here all day so yeah i've selected a few of more interesting ones and i hope you had a great time some takeaways that i would maybe hope to give you today so content and data we are building apis to provide some data some content

API Design - Getting Started—Alen Pokos


naming is a big part of our design as well as thinking about how we will name things and design choice design decisions are something that we do every day so it's not a matter of uh the best design choice it's a matter of is this design choice good for us sometimes there are several design choices that can be made that have a similar list of pros and cons it can be difficult but then it's just a matter of okay pick one and uh continue on uh when i talk about the api design and apis in general so this is this is not the all that it's covering

API Design - Getting Started—Alen Pokos


this uh this area there are some additional topics uh that could be covered like how can we do documentation on the api design uh how can we do a testing and validation of our apis versioning security so what kind of security are there not just authorization and authentication but also rate limits uh both protection topics like that there is also caching and backend speed optimizations there is some recipes that we can use to improve our apis like that and also a lot of implementation details on how can we implement our apis

API Design - Getting Started—Alen Pokos


so that is it for me uh and we can go over some of the questions uh and the q a uh you're muted dragon hi so let's see if uh we have any questions so far yeah yeah uh between okay okay so this is a question where do you draw the line between okay uh requirement engineering and api is the api design so the api design is uh i would say a result of the requirements uh so uh just like you do uh ux design sometimes the wireframes are part of the requirements uh but it's usually the requirements define what we need to achieve and the api

API Design - Getting Started—Alen Pokos


design is part of the technical solution how will we achieve our goal so uh if there is some uh let's put like this one thing that can affect the requirements if there is some design choice that can help us save money time and uh bring better results then we can go back to the requirements and ask for change but usually we have requirements and then we get then we go to the design stage uh does this answer your question great okay another question are we using swagger to build our api docs uh no right now we are using a postman uh

API Design - Getting Started—Alen Pokos


to document uh our apis and we also use it to test so right now this is uh the tool we are using uh we have used swagger to build some apis more specifically the open api specification okay another one is there anything that can help better visualizing the api design yes uh so um i'm thinking about how to answer because there are a couple of ways i can answer this uh so i don't know if there is any uh done tool like out of the box tool but one thing that we have been doing is building a map and this is one thing

API Design - Getting Started—Alen Pokos


that json api is really good because uh all the resources can be so basically adjacent api enables us to build a relational relationship uh of a relationship diagram of the whole uh api so yeah we have some tools that we developed to help us like build a uml diagram of all of our resources relationships attributes etc yeah okay a lot of questions uh this is a little bit of topic but uh yeah i know from ansible to uh thinking about it right now this uh out of the box yeah we've used ansible for some stuff we used custom solution for some type we

API Design - Getting Started—Alen Pokos


used uh symphony provided tools so uh yeah anything anything that works for you this is this is uh really specific to the technology stack to the solution to the infrastructure so there's a lot of factors i would say to answer this question a bit more fairly yeah uh recommendations on how to return errors to the client and what's the importance of using http state to status codes in the in this regard uh uh short answer json api uh so uh this is again a great thing about the standards that we use uh json api standard which already helps us

API Design - Getting Started—Alen Pokos


to describe how we should return errors what are the some of the status codes that are already part of the standards but there are some that we use customly so yeah i would say use it semantically if nobody hates me for saying it like that uh yeah so json api is really good for that uh it helps us a lot with this kind of questions yeah uh include testing in the process um i would say testing is part of the development process uh but again depending on which tools you use uh for the design so for example we use uh

API Design - Getting Started—Alen Pokos


postman for the api design itself so when we are done with the design we already have a complete postman collections and we can use it for testing we can also automate it so yeah so we can use it uh we can use it in that way oh i i love this one yeah uh i actually have on one slide uh prepared for this yeah this is this was uh a common common question um so uh the graphql is one of those technologies that we have used uh and um how to say it uh we've used with it uh it's they're pretty simple so despite they're being described as uh

API Design - Getting Started—Alen Pokos


data and this is a resource uh the json api for us has a clear conventions which helps us speed up the development process uh it has the right amount of implicit versus explicit so graphql is a great tool if you need a bit more let's say freedom but yeah if you like to design your own stuff but uh if you really want to use some standard json api works just fine and if you compare the two they can provide they provide pretty much the same uh functionality so yeah i i wouldn't say that either of them is uh better it's a personal taste maybe

API Design - Getting Started—Alen Pokos


okay regarding content of data how would you rate having values in field that reflect earnings instead of easily readable values so a philosopher philosophical answer here would be uh if you're using a strings or integers they're both atoms so we have a key that means something so if you use two or if you use call they are both kind of m's uh but yeah so uh this is this is an example where it's uh really good to separate the two uh pillars so from the back in perspective you're using number constants from the api perspective you want

API Design - Getting Started—Alen Pokos


something that is easily uh used by the client so i would probably most of the time i would prefer uh string so call something that when you look at the api as a per as a human or as a uh some kind of uh program you can you can then translate them into uh into your own values so if you use value two value two is very back in specific usually and if you use a uh call it describes the action so it doesn't matter what constant is behind it so yeah this is this kind of the answer this is a really good example where you

API Design - Getting Started—Alen Pokos


think about separating the back end from the api api is built for the consumer yeah hello girl uh how much an api script could be complex how do you snap involves in the performance issue um yeah this is a good question uh in short it so the performance of the json api really uh depends on your implementation because you can implement it to be really fast and we have had some good uh cases where our implementation was really fast but if we sometimes we weren't maybe so oriented on performances and yeah you can really quickly

API Design - Getting Started—Alen Pokos


degrade the performance but it's again it depends on your technological stack you can improve it but from our example uh a json api can be really performant so there isn't a lot of problems with getting it to be performed yeah uh have you heard of netjs framework uh i don't i cannot say i've heard it uh it sounds like it's a js framework so maybe i should ask if somebody from my front and colleagues is here to answer uh php typescript uh i mean in the company we so recorder is php based for the backend solutions uh

API Design - Getting Started—Alen Pokos


we use symphony but we also have uh build building a uh node.js based uh backend solution so we are using symphony and some node.js solutions in the company uh what is the preferred way to implement ignition api uh the json api way again this is uh this is a good question but we followed the json api specification and they just uh defined there's it basically are two main strategies how you can paginate one is offset limit and the other one is a page size so they the json api offers two ways you can pay in it depending on the

API Design - Getting Started—Alen Pokos


prefer preferences of the client can talk about the best practices of api version uh in my personal opinion yeah yeah okay i would maybe call it good practices best practices is uh this is kind of where it gets discussion oh something is better than the other um yeah i could talk about it i actually uh have uh in the in the longer version of this talk i actually mentioned a couple of things about the versioning so you could either a version by headers you can either version by url you can version by uh resource yeah uh

API Design - Getting Started—Alen Pokos


so i i would say not in the time that i have right now because it's a it's a really really uh a wide topic and i know there's a lot of options you can go with it okay thank you alan a lot of questions today we come to the end uh yeah just maybe to mention if you have any other questions feel free to contact me contact our company or send me an message on you know and the recording of this talk will be in couple you can come back to via developers website and and find the recording uh back to stephanie if he's still with us

API Design - Getting Started—Alen Pokos


if not thanks there okay i'm still alive uh there's another question right on implementing so this is kind of what i mentioned with uh constraints in the in the three uh main principles uh so if you standards you already have some rules in the place another big thing is uh naming so you if you have a ambiguous language some kind of uh dictionary that you agree with your business which is again something that can help uh and yeah that would be probably the two most important uh ones because if you standards if you use

API Design - Getting Started—Alen Pokos


hello everyone and welcome back to my channel today we're trying something a bit different which is I'm going to be talking about my research area today which is machine learning but I really hope that any of you guys that are coming from a non mathematical or computer background if you are watching along that you can understand this because I tried to make it understandable to a general audience and if you are watching anyways let me know in the comments below if you are able to follow along with this and if it made

Supervised vs Unsupervised vs Semi / Self Supervised vs Reinforcement Learning | Machine Learning


sense to you guys because I'm always trying to make sure that research areas can be accessible to everyone even if it's not your research area so I'm doing a PhD in computer science but my background is in maths and statistics and that's how I came across machine learning but some of you guys have been asking for me to do more machine learning on computer science videos and that's not something I really saw about doing on this channel but I did one to have it be more general PhD stuff but to kind of try this out for this month I


want to do one sort of day a week on machine learning or computer science programming that kind of thing one day a week on more general PhD stuff so that might be writing or skill so I've talked about transferable skills before so it could be something like that and then one day week that's more on the personal side of doing a PhD so things like routines weekly or daily vlogs which people have seem to respond really well to and things like you know financial aspects of being a PhD student side hustles for students all of that kind of


thing and then one day a week that's all the planning productivity stuff that tends to be what most people are interested in so that's kind of this the general plan I'm gonna have one of those each day and probably have one day of these study with me kind of videos as well but it is a lot so I'm gonna be trying that at this month seeing if it's something I can keep up with but what will be really important to me is understanding what is working for you guys so if there's a video style you like be sure you are liking be sure you


are commenting below and be sure you are subscribing because that's what helps me understand which videos are working and which ones I should continue doing so if you want me to continue doing one type of video be sure you're engaging with that video type or multiple video types if you love all the videos you want to see more videos about machine learning and my kind of research or PhD stuff in general then be sure you do subscribe and that you hit the notification valve so that you know when new videos are out


so this first video is going to be an introduction to machine learning in general just so you guys have a general understanding if anyone is like learning about machine learning for the first time here that you guys will have an understanding and then in future weeks we can get into some of the general algorithms and then as well I can show you the programming that goes alongside those things but let me know if you'd rather see more general stuff or you'd rather see things that I specifically used in my research so what is machine


learning so machine learning is a branch of artificial intelligence which is a technique that enables machines to act similarly to humans so trying to learn how to do things the same way that people do and then machine learning is a branch of that which uses statistical methods to enable machines to improve with experience so they learn based on their own experience and or from the experience that's in the data obviously so machine learning is essentially applied statistics so my background is in mathematics and statistics and that's


how I first learned about machine learning was in my degree in statistics and in my master's in data analytics so it's not 100% computer science it is more statistics you need kind of the mixture of statistics and computer science skills to be able to use machine learning and then deep learning I'm just going to mention briefly as well is another subcategory of machine learning and it's basically it has the ability to work with a multi-layer network of algorithms essentially of different layers of things going on and that's how


it makes decisions but before I get started with talking about data I just want to mention briefly as well I'm gonna be talking about features to do with data everyone in school probably would have done some form stats where you have different variables that are the input and then you have one that's the output so the features are the input variables so one example I'm going to talk about later is housing prices so the features might be the rooms the number of rooms and highest the number of bathrooms the square footage all of that stuff and


then the output variable will be the housing price that's associated so just to mention that briefly as well so I'm going to do some examples and I thought like how could I make these examples a bit different if anybody is familiar with machine learning so I decided to do things that are all based on YouTube so here we see one of my videos I'm actually wearing the same cost are kind of not ideal anyways so one of the things that YouTube offers the employees with speech recognition because you've got these captions that


are auto-generated it says that there on the screen that they are auto-generated meaning that I didn't provide the captions for this video instead they use a speech recognition software that turns my speech into text and that's automatically done and it's not always a hundred percent obviously especially when you have things like accents like I do say that I recorded in English from Ireland and then they obviously use some things so I mean that part already looks but it like looks like it's correct so that's good but that's one thing that


they do so that's an application of machine learning and sometimes some of these examples are also going to be using deep learning so it's hard to send a separate the two because you never know a lots of things that can be done using pure machine learning algorithms can also be done or are done with deep learning algorithms so the next thing that they do is spam classification so you see on my comments this is an YouTube studio but I have likely spam so they have they know when a couple of comments are going to be spammy so these


are people who comment down below subversive and things like that so they get put into the likely spam or they had helped to review and then I can go back and approve these comments time's comments that seem completely normal are come up with spam for some reason so it's not really 100% but you know like you know when Gmail obviously you've got your spam and that's pretty accurate like I've rarely ever had anybody anything in spam that's not spam so yeah so that's one thing that they do that's done with machine learning as


well so they learn the difference between spam and not spam by using they have examples of ones that have been labeled by people who said this is a spam email or this is an OnStar me mail and they learn how to categorize those as spam and not spam another thing that they do is text generation so you can see I have this comment here from eco wander shout-out to you for commenting on my video thank you so much you contribute to my growth here on youtube so thank you and and so you can see that YouTube has started


doing this in YouTube studio where you have like generated comments that you can just reply now I don't use those because obviously it's better to have longer comments if you want to get the engagement up so it looks better in the algorithm and it looks better for you guys if I'm doing longer comments and I'm engaging with you more when I can and so these are things that they do now though you can do automatically generated and that will be they'll read the machine learns how to understand the conflict the content of that comment and


what would be an appropriate response based on previous interactions they've seen on YouTube so they would have seen something similar to this on YouTube and had somebody some people are applying these kinds of comments and that's how they learn and that's how they come up with the responses and the last example that I'm going to show to do with ytube is recommender systems and that's really what I work in is recommender systems and you'll know this from things like Netflix or Amazon but as well YouTube does recommend you videos and you


homepage will be a recommended paint like a recommended set of videos that are specifically for you based on what you watched before and there's different ways that you can go by that so if you want to hear more about recommender systems that's my main research area that's the thing I know more about of like different ways that they can work so one way would be like people who like this video also liked this video and then another is you know finding similarities between the videos themselves and not actually taking into


account the human side of things and then another thing would be taking into account people that are similar to you and finding what kind of videos they liked so um there's just a couple different ways if you want to hear more about recommender systems let me know in the comments below so now we're going to go into the types of learning algorithms very basic introduction to these different learning algorithms and just so that you have an understanding of the basic categories of machine learning so supervised learning and the first one


we're going to talk about so the the main two categories are supervised and unsupervised learning but then there's also subcategories they're like semi-supervised and self supervised learning I'm gonna talk about those and then there's also reinforcement learning so I'm gonna talk about all of these in this video and but supervised learning basically what that means is you have a training data set with Associated labels so you essentially know the right answer in this situation and these labels have been provided by a human supervisor so


somebody has labeled this data set so I've got the example that I was talking about here so we know the size of a house we know the amenities whether it's said facing your north's facing all of that kind of thing and then the accompanying housing price was obtained from whenever the house was sold so we have this training data which is actual houses and the actual housing prices they sell - and then you want to learn how to form the housing price based on the description so we have a description solution and we want to learn a general


solution for when we have new descriptions but no solutions so for example we have a new house coming onto the market we know all of the information obviously we know that number of rooms number of bathrooms all of that stuff but obviously it hasn't gone to market we don't know the price but we can use the previous examples we can train a model on this data to kind of come up with an estimate of the housing price based on the fact that we don't know based on all the information we do know so that's the general


supervised problem is we have training data with labels and we want to learn based on the training data features what would the label be and what issue with supervised learning always is that it's very hard to find label data and for bigger free for problems that have a ton of different options it can be hard to do so for example in speech recognition you know there's an endless number of combinations of words that could be said so to get somebody to come up with all of the possible sentences ever like that's not possible and then